Finds themedian value of an array, or applies a one- or two-dimensional median filter of a specified width to an array.
width (optional) The length of the one- or two-dimensional neighborhood to be used for the median filter. Must be a scalar value, greater than 1 and less than the smaller of the dimensions of array. The neighborhood will have the same number of dimensions as array.
NOTE: The Average keyword is ignored when filtering a byte array.
'copy'
) Valid strings are:
'zero'
Sets the border of the output image to zero.
'copy'
Copies the border of the input image to the output image. (Default)
Median smoothing replaces each point with the median of the one- or two-dimensional neighborhood of the given width. It is similar to smoothing with a boxcar or average filter, but does not blur edges larger than the neighborhood. In addition, median filtering is effective in removing "salt and pepper" noise (isolated high or low values).
The scalar median is simply the middle value, which should not be confused with the average value (e.g., the median of [1, 10, 4] is 4, while the average is 5).
OPENR, unit, FILEPATH('head.img', Subdir = 'data'), /Get_Lun
; Open the file containing the human head dataset.
head = BYTARR(512, 512)
; Create an array large enough to hold the dataset.
READU, unit, head FREE_LUN, unit
; Read the data, then close the file and free the file unit number.
slice = CONGRID(REFORM(head), 256, 256, /Interp)
; Use REFORM to remove degenerate dimensions, then resize the
; image using the CONGRID function.
WINDOW, 0, Xsize = 768, Ysize = 256
LOADCT, 3
; Load the red temperature color table.
TVSCL, slice, 0
; Display the original image in the leftmost portion of the window.
HIST_EQUAL_CT, slice
; Histogram equalize the color table.
.RUN FOR i = 0, 253, 6 DO BEGIN
rows = RANDOM(256) GT 0.5
k = RANDOM(1)
h = 3 * (k(0) GT 0.5)
FOR j = h, 253, 6 DO BEGIN
IF rows(j) THEN slice(i:i + 2, j:j + 2) = 0
ENDFOR
; This FOR loop creates 3-by-3 isolated holes in the image.
ENDFOR END TVSCL, slice, 256, 0
filtered = MEDIAN(slice, 5)
; Median filter the image with holes.
TVSCL, filtered, 512, 0
; Display the median filtered image in the rightmost portion of the window.
Figure 2-55 Original image (left), corrupted image (center), and median filtered image (right).
Figure 2-56 Original image (left), corrupted image (center), and median filtered image (right).