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

From MIPAV
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
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
== Background ==
The Median filter algorithm replaces a target pixel's value with the median value of the neighboring pixels. The designation of ''neighbor'' is determined by the size and shape of the kernel. A kernel is much like a mask; the pixels in the masked area are part of the neighborhood. The kernel's size and shape determines the number of pixel values used to calculate the median. You can adjust this algorithm's parameters to change the kernel's size and shape, apply selective filtering, and repetitively apply the selected filtering for any portion of the image you select.


;; Mean = sum of all pixels in the kernel / total number of pixels in the kernel
The median filter algorithm is most useful for removing ''shot noise'', which is noise that appears as random spots in an image. Shot noise can be caused by dust or a bad detector in image acquisition or by errors in data transfer (Lyon, Russ). Note that because there is no inverse function for the median filter algorithm, the original image cannot be reconstructed. This algorithm is also called a ''rank-type filter,'' because the list of values must be sorted before a useful value can be found.
 
This is one method of low-pass filtering, which is sometimes referred to as ''neighborhood averaging''.
 
=== 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:
 
<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.
 
<div> </div>


{| width="90%" border="1" frame="hsides" frame="hsides"
{| width="90%" border="1" frame="hsides" frame="hsides"
|-
|-
| width="9%" valign="top" |
| width="9%" valign="top" |
[[Image:exampleicon.gif]]
[[Image:noteicon.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.
| width="81%" bgcolor="#B0E0E6" |
[http://mipav.cit.nih.gov/ For more information about the algorithm, refer to MIPAV Volume 2 User Guide on the MIPAV web site:{http://mipav.cit.nih.gov/} ]
|}
|}


<br />
<br />


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.
== Image types ==


<div>
You can apply this algorithm to color and gray-scale 2D, 2.5D, and 3D images. However, you cannot apply this algorithm to complex images.


{| border="1" cellpadding="5"
<div> </div>
|+ <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><div><center>[[Image:exampleSliceAveragingTargetPixels.jpg]]</center></div> </div>
|}


</div>
== Special notes ==


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 following special notes apply:


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.
* When this algorithm is applied to 3D datasets, you can apply the filter to either a single slice or volume kernel. If you choose to apply it to a volume kernel, MIPAV finds the median in a list of values from pixels in all directions along the ''x''-, ''y''-, and ''z''-axes. Note that the kernel-size must be smaller than the number of slices in the image.
* The resultant image is, by default, a float image.
* An outlier detector is available for use in this algorithm. The outlier detector replaces the target pixel only if its magnitude exceeds the mean of the list by a user-inputted fraction of the standard deviation.
* Currently the algorithm allows square and cross kernel shapes for 2D images and cube and axis kernel shapes for 3D images. Future plans include the addition of other kernel shapes.
* Color images may be filtered across any combination of the color channels (red, green, or blue). Alpha values-those values relating to how opaque a particular pixel is-are unaffected.


{| border="1" cellpadding="5"
<div> </div>
|+ <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>
|-
|
[[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.
 
==== Image types ====
 
You can apply this algorithm to all image data types and to 2D, 2.5D, and 3D images.
 
==== Special notes ====


None.
== Applying the Median Filter algorithm ==
 
==== References ====
 
Refer to the following reference for more information about this algorithm:
 
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 ===


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.
# Select Algorithms &gt; Filter &gt; Median Filter. The Median Filter dialog box appears.
# Select Algorithms &gt; Filter (spatial) &gt; Mean. The Mean Filter dialog box (Figure 3) opens.
# Complete the fields in the dialog box. Keep the following in mind:
# Complete the information in the dialog box.
#* To filter a VOI region only, select the VOI and then select VOI Region(s).
# Click OK.
#* Pixels that are too close to the edge of an image are not processed.
#* To apply a median filter to a color image, select the channels to filter. By default, MIPAV filters all three channels (red, green, and blue).
# 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, and the following message appears: "Filtering Image (Pass 1 of 1)." (Depending on what you entered in Number of iterations on the Median Filter dialog box, the number of passes varies.) When the algorithm finishes running, the pop-up window closes.
; 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.
; 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>
<div>


{| border="1" cellpadding="5"
{| border="1" cellpadding="5"
|+ <div>'''Figure 3. Mean Filter dialog box''' </div>
|+ <div>'''Figure 1. Median Filter dialog box ''' </div>
|-
|
<div>'''Number of iterations''' </div>
|
<div>Indicates the number of times to filter the image with a median filter of the selected deviation, kernel size, and kernel shape. </div>
| rowspan="3" colspan="1" |
<div> </div><div><div><center>[[Image:MedianFilterdialogBox.jpg]]</center></div> </div>
|-
|
<div>'''Maximum standard deviation''' </div>
|
<div>The maximum allowable magnitude of the pixel value as a function of the standard deviation. The system replaces any pixel whose value is outside this function of the standard deviation from the mean of the neighborhood (as selected by the kernel-size and shape) by the median of the neighborhood. A value of 0.0 is equivalent to replacing every pixel with the median of its neighborhood. A value of 1.0 limits the filtering of the image. The system processes only target pixels whose values are greater than 1.0 standard deviation from its neighbors. </div>
|-
|-
|
|
<div>'''Kernel size''' </div>
<div>'''Kernel size''' </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>
<div>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. </div>
| rowspan="7" colspan="1" |
|-
<div><div><center>[[Image:dialogboxMean.jpg]]</center></div> </div><div> </div>
|
<div>'''Kernel shape''' </div>
| rowspan="1" colspan="2" |
<div>Selects which pixels in the kernel size box are included as a part of the median's neighborhood. </div>
|-
|
<div>Kernel size adaptively changes </div>
| rowspan="1" colspan="2" |
<div>This checkbox indicates whether median filter should be run via adaptive filtering. Adaptive filtering has 3 main purposes:  </div><div>1. To remove salt-and-pepper (impulse) noise;  </div><div>2. To prove smoothing of other noise that may not be impulsive; </div><div>3. And to reduce distortion, such as excessive thinning or thickening of object borders. </div>
|-
|
<div>Maximum Kernel Size </div>
| rowspan="1" colspan="2" |
<div> This is the maximum kernel size that the window size can get increased to under the algorithm. </div>
|-
|-
|
|
<div>'''Red channel''' </div>
<div>'''Red channel''' </div>
|
| rowspan="1" colspan="2" |
<div>Applies the algorithm to the red channel. </div>
<div>Filters the red channel (for use with RGB images). </div>
|-
|-
|
|
<div>'''Green channel''' </div>
<div>'''Green channel''' </div>
|
| rowspan="1" colspan="2" |
<div>Applies the algorithm to the green channel. </div>
<div>Filters the green channel (for use with RGB images). </div>
|-
|-
|
|
<div>'''Blue channel''' </div>
<div>'''Blue channel''' </div>
|
| rowspan="1" colspan="2" |
<div>Applies the algorithm to the blue channel. </div>
<div>Filters the blue change (for use with RGB images). </div>
|-
|-
|
|
<div>'''New image''' </div>
<div>'''New image''' </div>
|
| rowspan="1" colspan="2" |
<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>
|
| rowspan="1" colspan="2" |
<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 121:
<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 Median algorithm according to the specifications in this dialog box. </div>
|-
|-
|
|
Line 157: Line 144:
|}
|}


</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 />
== See also: ==
**[[Filters (Spatial): Adaptive Path Smooth]]
**[[Filters (Spatial) Anisotropic Diffusion]]
**[[Filters (Spatial): Coherence-Enhancing Diffusion]]
**[[Filters (Spatial): Gaussian Blur]]
**[[Filters (Spatial): Gradient Magnitude]]
**[[Filters (Spatial): Haralick Texture]]
**[[Filters (Spatial) Laplacian]]
**[[Filters (Spatial): Local Normalization]]
**[[Filters (Spatial): Mean]]
 


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

Latest revision as of 16:28, 9 February 2024

Background

The Median filter algorithm replaces a target pixel's value with the median value of the neighboring pixels. The designation of neighbor is determined by the size and shape of the kernel. A kernel is much like a mask; the pixels in the masked area are part of the neighborhood. The kernel's size and shape determines the number of pixel values used to calculate the median. You can adjust this algorithm's parameters to change the kernel's size and shape, apply selective filtering, and repetitively apply the selected filtering for any portion of the image you select.

The median filter algorithm is most useful for removing shot noise, which is noise that appears as random spots in an image. Shot noise can be caused by dust or a bad detector in image acquisition or by errors in data transfer (Lyon, Russ). Note that because there is no inverse function for the median filter algorithm, the original image cannot be reconstructed. This algorithm is also called a rank-type filter, because the list of values must be sorted before a useful value can be found.

Noteicon.gif

For more information about the algorithm, refer to MIPAV Volume 2 User Guide on the MIPAV web site:{http://mipav.cit.nih.gov/}


Image types

You can apply this algorithm to color and gray-scale 2D, 2.5D, and 3D images. However, you cannot apply this algorithm to complex images.

Special notes

The following special notes apply:

  • When this algorithm is applied to 3D datasets, you can apply the filter to either a single slice or volume kernel. If you choose to apply it to a volume kernel, MIPAV finds the median in a list of values from pixels in all directions along the x-, y-, and z-axes. Note that the kernel-size must be smaller than the number of slices in the image.
  • The resultant image is, by default, a float image.
  • An outlier detector is available for use in this algorithm. The outlier detector replaces the target pixel only if its magnitude exceeds the mean of the list by a user-inputted fraction of the standard deviation.
  • Currently the algorithm allows square and cross kernel shapes for 2D images and cube and axis kernel shapes for 3D images. Future plans include the addition of other kernel shapes.
  • Color images may be filtered across any combination of the color channels (red, green, or blue). Alpha values-those values relating to how opaque a particular pixel is-are unaffected.

Applying the Median Filter algorithm

To run this algorithm, complete the following steps:

  1. Select Algorithms > Filter > Median Filter. The Median Filter dialog box appears.
  2. Complete the fields in the dialog box. Keep the following in mind:
    • To filter a VOI region only, select the VOI and then select VOI Region(s).
    • Pixels that are too close to the edge of an image are not processed.
    • To apply a median filter to a color image, select the channels to filter. By default, MIPAV filters all three channels (red, green, and blue).
  3. Click OK when complete. The algorithm begins to run.
A pop-up window appears with the status, and the following message appears
"Filtering Image (Pass 1 of 1)." (Depending on what you entered in Number of iterations on the Median Filter dialog box, the number of passes varies.) 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 1. Median Filter dialog box
Number of iterations
Indicates the number of times to filter the image with a median filter of the selected deviation, kernel size, and kernel shape.
MedianFilterdialogBox.jpg
Maximum standard deviation
The maximum allowable magnitude of the pixel value as a function of the standard deviation. The system replaces any pixel whose value is outside this function of the standard deviation from the mean of the neighborhood (as selected by the kernel-size and shape) by the median of the neighborhood. A value of 0.0 is equivalent to replacing every pixel with the median of its neighborhood. A value of 1.0 limits the filtering of the image. The system processes only target pixels whose values are greater than 1.0 standard deviation from its neighbors.
Kernel size
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.
Kernel shape
Selects which pixels in the kernel size box are included as a part of the median's neighborhood.
Kernel size adaptively changes
This checkbox indicates whether median filter should be run via adaptive filtering. Adaptive filtering has 3 main purposes:
1. To remove salt-and-pepper (impulse) noise;
2. To prove smoothing of other noise that may not be impulsive;
3. And to reduce distortion, such as excessive thinning or thickening of object borders.
Maximum Kernel Size
This is the maximum kernel size that the window size can get increased to under the algorithm.
Red channel
Filters the red channel (for use with RGB images).
Green channel
Filters the green channel (for use with RGB images).
Blue channel
Filters the blue change (for use with RGB images).
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 Median 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.

See also: