Filters (Spatial): Mean and Filters (Spatial): Mode: Difference between pages

From MIPAV
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
MIPAV>Olgavovk
mNo edit summary
 
Line 1: Line 1:
This algorithm provides a simple way of reducing noise either in an entire image or in a delineated VOI in the image where
Mode filtering is a nonlinear spatial filtering technique that replaces a target pixel with the mode of neighboring pixels. The ''mode'' of a set of values is the value that occurs most frequently within the set. If all values are unique-that is, all numbers occur only once in the set-the value of the target pixel stays the same. Mode filtering is similar in philosophy to median filtering.


;; Mean = sum of all pixels in the kernel / total number of pixels in the kernel
Mode filtering is currently thought to be useful in filtering a segmented image to eliminate small clusters of pixels labeled one value that are completely within a large cluster of pixels of a different value. Mode filtering is currently being investigated in improving a C-means classification of brain images, which were first segmented using the brain extraction tool (BET). Mode filtering can be applied to grayscale images to remove some noise; however, a 3 x 3 x 3 cube kernel significantly blurs the image.
 
This is one method of low-pass filtering, which is sometimes referred to as ''neighborhood averaging''.


=== Background ===
=== Background ===


In applying this algorithm, MIPAV first defines a region, either in the whole image or in the delineated VOI, over which it replaces a target pixel value with the average value over the kernel of pixels in which the target pixel is at the center. That is, for the target pixel:
When you apply the Mode algorithm, MIPAV identifies the target pixel and collects the values of the surrounding neighborhood. Next, it arranges the values of the target and neighborhood pixels in a list and sorts them. The value of the target pixel is replaced with the mode of the numbers in the list. Determining the mode of a sorted list of numbers is done in a single pass through the list by incrementing a count variable each time adjacent values are the same and maintaining the maximum count along with the corresponding value.
 
<math>
mean = \frac {1} {s} \sum_{i=1}^{i=s} I_i k_i
</math>
 
where ''k ''''<nowiki>= kernel,</nowiki>'''' s'' = kernel size, and ''I'' = image.
 
For ''slice averaging ''(Figure 1] and (Figure2), the kernels are odd-length squares (for example, 3 x 3). The processing time increases with the square of the kernel length. For'' volume averaging ''( Figure 2), the kernels are odd-length cubes (such as 5 x 5 x 5), and the processing time increases with the cube of the kernel length. Refer to Figure 2 for examples of slice and volume averaging.
 
Note that the term ''average'' does not always represent the mean. If fact, there are three types of average: the commonly used mean, the median, and the infrequently used mode. The ''mean'' is defined as the sum of the values in a group divided by the number of values in the group. The ''median'' value is the value that has the same number of values greater and less than it. The ''mode'' is the value with the greatest number of occurrences.


If part of the neighborhood kernel falls outside the image when the pixel is on or near the boundary, MIPAV only uses that portion of the kernel inside the image.
Neighborhood pixels are determined by the shape and size of the kernel. (The selection of pixels using the kernel is sometimes referred to as the ''sliding window approach''.) The most common kernel shapes are the square and cross.


<div> </div>
Square-shaped kernels are defined as all pixels in the ''k''(''k'') region surrounding the target pixel, where k refers to the window size. Cross-shaped kernels are defined as the central row and column of the ''k''(''k'') region.


{| width="90%" border="1" frame="hsides" frame="hsides"
The kernel is usually centered on the target pixel and is symmetrical; pixels chosen are symmetrically located about the target pixel. Thus, pixels on opposite sides are equally weighted. The kernel varies in size, although commonly a square kernel can range from 3 to 11 pixels per side. Other kernel shapes and sizes could be selected, but choosing the region of pixels to include always involves juggling the elimination of noise and increasing fuzziness and posterization of an image.
|-
| width="9%" valign="top" |
[[Image:exampleicon.gif]]
| width="81%" bgcolor="#B0E0E6" | '''Example:''' Consider the upper right corner pixel in a 2D image if a 3 x 3 kernel is used. In this case, when the algorithm is applied, MIPAV uses only the target pixel and its lower, left, and diagonal left lower neighbors. It then divides the sum of these four pixels by 4.
|}


<br />
Pixel values are sorted in increasing order. Any sorting method is acceptable, although, because the number of pixels can be large, a fast- sorting algorithms is preferable. The best sorting algorithm is one that can efficiently accommodate both small and large lists. Generally, when considering the number of items to sort, the numbers can range from 5 (in a 3 x 3 cross) to 121 (in an 11 x 11 square). This algorithm implements the Shell-sort because it operates very efficiently for the sizes of the lists expected.


If you select the New image option, MIPAV places the resulting image in a new image window. If you select the Replace image option, MIPAV returns the changed picture to the same image window. If you delineate a VOI on the image and select VOI regions, then MIPAV replaces the original value of a pixel inside the VOI with the mean value of the kernel that contains the pixel at its center. The pixel values outside the VOI remain unchanged.
The left image in Figure 1 shows a segmented image that results after applying the C-means classification algorithm to a brain image produced with the brain extraction tool. The image on the right shows the result of applying the Mode filtering algorithm with a 3 x 3 x 3 local neighborhood to the image on the left. Clearly, the image on the right has fewer small isolated classes than the image on the left.


<div>
<div>


{| border="1" cellpadding="5"
{| border="1" cellpadding="5"
|+ <div>'''Figure 1. Slice averaging''' </div> In slice averaging, MIPAV defines a region and replaces the target pixel value with the average value over the kernel of pixels in which the target pixel is at the center.
|+ <div>'''Figure 1. Examples of (A) a segmented image and (B) the results of applying the Mode algorithm to the image''' </div>
|-
|-
|
|
<div><div><center>[[Image:exampleSliceAveragingTargetPixels.jpg]]</center></div> </div>
<div><div><center>[[Image:exampleMode1.jpg]]</center></div> </div>
|
<div><div><center>[[Image:exampleMode2.jpg]]</center></div> </div>
|}
|}


  </div>
  </div>


Because 2D images contain only one slice, the only option possible under Kernel Thickness in the Mean Filter dialog box is slice averaging-the Apply slice kernel option. The Apply volume kernel option, which performs volume averaging, is dimmed. However, both slice averaging and volume averaging are available for 3D images. Although slice averaging is the default value, users can choose volume averaging instead by selecting the Apply volume kernel option.
The Mode algorithm processes all pixels in the input image. The algorithm uses a symmetric neighborhood definition around the target pixel, resulting in border pixels, which require special processing. Border pixels correspond to those pixels where the neighborhood of a target pixel is incomplete. Incomplete neighborhoods occur:
 
For slice averaging, the default kernel size is 3 x 3, but the following kernel sizes are available: 5 x 5, 7 x 7, 9 x 9, or 11 x 11. For volume averaging, the default kernel size is 3 x 3 x 3. However, you can select one of the following sizes instead: 5 x 5 x 5, 7 x 7 x7, 9 x 9 x 9, or 11 x 11 x 11.


{| border="1" cellpadding="5"
* ''In-plane''-In the corners of the image plane
|+ <div>'''Figure 2. Image processing using the Mean algorithm''' </div><div>This figure depicts slice averaging and volume averaging applied to the whole image with various size kernels as noted. </div>
* ''Through-plane''-On the first and last (few) image planes
|-
|
[[Image:exampleMeanProcessing.jpg]]
|}


For color images the default is to obtain the means of the red, green, and blue channels. However, if users clear the Red channel, Green channel, or Blue channel check boxes, MIPAV only performs mean averaging on the color channels that are selected.
In-plane border pixels are not filtered and the value assigned to the output pixel is simply the corresponding input value. Through-plane border pixels are filtered by duplicating the values of corresponding pixels on the target pixel plane.


==== Image types ====
==== Image types ====


You can apply this algorithm to all image data types and to 2D, 2.5D, and 3D images.
You can apply this algorithm to 2D, 2.5D, and 3D images. Since the algorithm counts the number of pixels with the same value, it only allows the following list of data types.
 
* BYTE and UBBYTE
* SHORT and USHORT
* INTEGER and UINTEGER


==== Special notes ====
==== Notes ====


None.
The resulting image is, by default, the same type as the input image.


==== References ====
==== References ====


Refer to the following reference for more information about this algorithm:
This algorithm was developed by members of the MIPAV team. Mode filtering is similar to median filtering, and to our knowledge there is not a significant amount of literature about the topic.
 
Raphael C. Gonzalez and Richard E. Woods. ''Digital Image Processing'', Second Edition (Upper Saddle River, New Jersey: Prentice-Hall, Inc., 2002), pp. 116-123.


=== Applying the Mean algorithm ===
=== Applying the Mode algorithm ===


To run this algorithm, complete the following steps:
To run this algorithm, complete the following steps:


# Open an image. As an option, delineate a VOI.
# Open an image.
# Select Algorithms &gt; Filter (spatial) &gt; Mean. The Mean Filter dialog box (Figure 3) opens.
# Select Algorithms &gt; Filters (Spatial) &gt; Mode. The Mode Filter dialog box ([FiltersSpatialMode.html#wp1006320 Figure 35]) opens.
# Complete the information in the dialog box.
# Complete the fields in the dialog box.
# Click OK.
# Click OK when complete. The algorithm begins to run.


; The algorithm begins to run, and a pop-up window appears with the status. The following message appears: "Filtering image."
; A pop-up window appears with the status.
; When the algorithm finishes running, the pop-up window closes, and the results either appear in a new window or replace the image to which the algorithm was applied.


<div>
<div>


{| border="1" cellpadding="5"
{| border="1" cellpadding="5"
|+ <div>'''Figure 3. Mean Filter dialog box''' </div>
|+
|-
|-
|
|
<div>'''Kernel size''' </div>
<div><div><center>[[Image:messageModeFiltering.jpg]]</center></div> </div>
|
|}
<div>Specifies the size of the ''k'' x ''k'' neighborhood that extends in all directions by (''k ''- 1)/2 from the center pixel. </div>
 
| rowspan="7" colspan="1" |
</div>
<div><div><center>[[Image:dialogboxMean.jpg]]</center></div> </div><div> </div>
 
; When the algorithm finishes running, the pop-up window closes.
; Depending on whether New image or Replace image was selected, results appear in a new window or replace the image to which the algorithm was applied.
 
<div>
 
{| border="1" cellpadding="5"
|+ <div>'''Figure 2. Mode Filter dialog box ''' </div>
|-
|-
|
|
<div>'''Red channel''' </div>
<div>'''Kernel size''' </div>
|
<div>Applies the algorithm to the red channel. </div>
|-
|
<div>'''Green channel''' </div>
|
|
<div>Applies the algorithm to the green channel. </div>
<div>Specifies the size of the local neighborhood when performing mode filtering. A ''k'' x ''k'' region selects a neighborhood that extends in all directions by (''k'' - 1)/2 placing the target pixel in the center of the kernel. Kernels for 2D images are odd valued and include 3 x 3, 5 x 5, 7 x 7, and so on. </div>
| rowspan="4" colspan="1" |
<div><div><center>[[Image:dialogboxModeFilter.jpg]]</center></div> </div>
|-
|-
|
|
<div>'''Blue channel''' </div>
<div>'''Kernel shape''' </div>
|
|
<div>Applies the algorithm to the blue channel. </div>
<div>Selects which pixels in the kernel size box are included as a part of the mode's neighborhood. </div>
|-
|-
|
|
<div>'''New image''' </div>
<div>'''New image''' </div>
|
|
<div>Shows the results of the algorithm in a new image window. </div>
<div>Indicates where the results of the algorithm appear. If you select this option, the results appear in a new image window. </div>
|-
|-
|
|
<div>'''Replace image''' </div>
<div>'''Replace image''' </div>
|
|
<div>Replaces the current active image with the newly calculated mean image. </div>
<div>Indicates where the results of the algorithm appear. If you select this option, the results replace the current active image. </div>
|-
|-
|
|
<div>'''Whole image''' </div>
<div>'''Whole image''' </div>
|
| rowspan="1" colspan="2" |
<div>Applies the algorithm to the whole image. </div>
<div>Applies the algorithm to the whole image. </div>
|-
|-
|
|
<div>'''VOI regions''' </div>
<div>'''VOI region(s)''' </div>
| rowspan="1" colspan="2" |
| rowspan="1" colspan="2" |
<div>Applies the algorithm to the volumes (regions) delineated by the VOIs. </div>
<div>Applies the algorithm to the volumes (regions) delineated by the VOIs. </div>
Line 134: Line 118:
<div>'''Apply slice kernel''' </div>
<div>'''Apply slice kernel''' </div>
| rowspan="1" colspan="2" |
| rowspan="1" colspan="2" |
<div>Applies the kernel to only the specific slice in the dataset </div>
<div>Filters each slice of the image independently of other slices, finding neighboring pixels from the slice. </div>
|-
|-
|
|
<div>'''Apply volume kernel''' </div>
<div>'''Apply volume kernel''' </div>
| rowspan="1" colspan="2" |
| rowspan="1" colspan="2" |
<div>Applies the kernel to all of the slices-that is, the entire volume-in the dataset. </div>
<div>Gathers pixel values from the slice as well as from neighboring slices. </div>
|-
|-
|
|
<div>'''OK''' </div>
<div>'''OK''' </div>
| rowspan="1" colspan="2" |
| rowspan="1" colspan="2" |
<div>Applies the mean algorithm according to the specifications in this dialog box. </div>
<div>Applies the Mode filtering algorithm according to the specifications in this dialog box. </div>
|-
|-
|
|
Line 156: Line 140:
<div>Displays online help for this dialog box. </div>
<div>Displays online help for this dialog box. </div>
|}
|}
</div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 18pt; margin-right: 0pt; margin-top: 6pt; text-align: left; text-decoration: none; text-indent: 0pt; text-transform: none; vertical-align: baseline"><font size="11pt"><font color="#000000"><br />


[[Category:Help]]
[[Category:Help]]
[[Category:Help:Algorithms]]
[[Category:Help:Algorithms]]

Revision as of 18:26, 18 May 2012

Mode filtering is a nonlinear spatial filtering technique that replaces a target pixel with the mode of neighboring pixels. The mode of a set of values is the value that occurs most frequently within the set. If all values are unique-that is, all numbers occur only once in the set-the value of the target pixel stays the same. Mode filtering is similar in philosophy to median filtering.

Mode filtering is currently thought to be useful in filtering a segmented image to eliminate small clusters of pixels labeled one value that are completely within a large cluster of pixels of a different value. Mode filtering is currently being investigated in improving a C-means classification of brain images, which were first segmented using the brain extraction tool (BET). Mode filtering can be applied to grayscale images to remove some noise; however, a 3 x 3 x 3 cube kernel significantly blurs the image.

Background

When you apply the Mode algorithm, MIPAV identifies the target pixel and collects the values of the surrounding neighborhood. Next, it arranges the values of the target and neighborhood pixels in a list and sorts them. The value of the target pixel is replaced with the mode of the numbers in the list. Determining the mode of a sorted list of numbers is done in a single pass through the list by incrementing a count variable each time adjacent values are the same and maintaining the maximum count along with the corresponding value.

Neighborhood pixels are determined by the shape and size of the kernel. (The selection of pixels using the kernel is sometimes referred to as the sliding window approach.) The most common kernel shapes are the square and cross.

Square-shaped kernels are defined as all pixels in the k(k) region surrounding the target pixel, where k refers to the window size. Cross-shaped kernels are defined as the central row and column of the k(k) region.

The kernel is usually centered on the target pixel and is symmetrical; pixels chosen are symmetrically located about the target pixel. Thus, pixels on opposite sides are equally weighted. The kernel varies in size, although commonly a square kernel can range from 3 to 11 pixels per side. Other kernel shapes and sizes could be selected, but choosing the region of pixels to include always involves juggling the elimination of noise and increasing fuzziness and posterization of an image.

Pixel values are sorted in increasing order. Any sorting method is acceptable, although, because the number of pixels can be large, a fast- sorting algorithms is preferable. The best sorting algorithm is one that can efficiently accommodate both small and large lists. Generally, when considering the number of items to sort, the numbers can range from 5 (in a 3 x 3 cross) to 121 (in an 11 x 11 square). This algorithm implements the Shell-sort because it operates very efficiently for the sizes of the lists expected.

The left image in Figure 1 shows a segmented image that results after applying the C-means classification algorithm to a brain image produced with the brain extraction tool. The image on the right shows the result of applying the Mode filtering algorithm with a 3 x 3 x 3 local neighborhood to the image on the left. Clearly, the image on the right has fewer small isolated classes than the image on the left.

Figure 1. Examples of (A) a segmented image and (B) the results of applying the Mode algorithm to the image
ExampleMode1.jpg
ExampleMode2.jpg

The Mode algorithm processes all pixels in the input image. The algorithm uses a symmetric neighborhood definition around the target pixel, resulting in border pixels, which require special processing. Border pixels correspond to those pixels where the neighborhood of a target pixel is incomplete. Incomplete neighborhoods occur:

  • In-plane-In the corners of the image plane
  • Through-plane-On the first and last (few) image planes

In-plane border pixels are not filtered and the value assigned to the output pixel is simply the corresponding input value. Through-plane border pixels are filtered by duplicating the values of corresponding pixels on the target pixel plane.

Image types

You can apply this algorithm to 2D, 2.5D, and 3D images. Since the algorithm counts the number of pixels with the same value, it only allows the following list of data types.

  • BYTE and UBBYTE
  • SHORT and USHORT
  • INTEGER and UINTEGER

Notes

The resulting image is, by default, the same type as the input image.

References

This algorithm was developed by members of the MIPAV team. Mode filtering is similar to median filtering, and to our knowledge there is not a significant amount of literature about the topic.

Applying the Mode algorithm

To run this algorithm, complete the following steps:

  1. Open an image.
  2. Select Algorithms > Filters (Spatial) > Mode. The Mode Filter dialog box ([FiltersSpatialMode.html#wp1006320 Figure 35]) opens.
  3. Complete the fields in the dialog box.
  4. Click OK when complete. The algorithm begins to run.
A pop-up window appears with the status.
MessageModeFiltering.jpg
When the algorithm finishes running, the pop-up window closes.
Depending on whether New image or Replace image was selected, results appear in a new window or replace the image to which the algorithm was applied.
Figure 2. Mode Filter dialog box
Kernel size
Specifies the size of the local neighborhood when performing mode filtering. A k x k region selects a neighborhood that extends in all directions by (k - 1)/2 placing the target pixel in the center of the kernel. Kernels for 2D images are odd valued and include 3 x 3, 5 x 5, 7 x 7, and so on.
DialogboxModeFilter.jpg
Kernel shape
Selects which pixels in the kernel size box are included as a part of the mode's neighborhood.
New image
Indicates where the results of the algorithm appear. If you select this option, the results appear in a new image window.
Replace image
Indicates where the results of the algorithm appear. If you select this option, the results replace the current active image.
Whole image
Applies the algorithm to the whole image.
VOI region(s)
Applies the algorithm to the volumes (regions) delineated by the VOIs.
Apply slice kernel
Filters each slice of the image independently of other slices, finding neighboring pixels from the slice.
Apply volume kernel
Gathers pixel values from the slice as well as from neighboring slices.
OK
Applies the Mode filtering algorithm according to the specifications in this dialog box.
Cancel
Disregards any changes that you made in this dialog box and closes the dialog box.
Help
Displays online help for this dialog box.