Local range of image
J = rangefilt(I)
J = rangefilt(I,nhood)
Read an image into the workspace.
I = imread('liftingbody.png');
Filter the image. The
rangefilt function returns an array where each output pixel contains the range value (maximum value - minimum value) of the 3-by-3 neighborhood around the corresponding pixel in the input image.
J = rangefilt(I);
Display the original image and the filtered image side-by-side.
Read image into the workspace.
I = imread('autumn.tif');
Convert the RGB image into a L*a*b* image.
cform = makecform('srgb2lab'); LAB = applycform(I, cform);
Perform the range filtering on the LAB image.
rLAB = rangefilt(LAB);
Display the images.
Read an image into the workspace, and display it.
I = imread('circuit.tif'); imshow(I);
Define a neighborhood. In this example, the neighborhood returns a large value when there is a large difference between pixel values to the left and right of an input pixel. The filtering does not consider pixels above and blow the input pixel. Thus, this neighborhood emphasizes vertical edges.
nhood = [1 1 1];
Perform the range filtering operation using this neighborhood. For comparison, also perform range filtering using the default 3-by-3 neighborhood. Compare the results.
J = rangefilt(I,nhood); K = rangefilt(I); figure imshowpair(J,K,'montage'); title('Range filtering using specified neighborhood (left) and default neighborhood (right)');
The result using the specified neighborhood emphasizes vertical edges, as expected. In comparison, the default filter is not sensitive to edge directionality.
I— Image to be filtered
Image to be filtered, specified as a real, nonsparse, numeric array of any dimension.
true(3)(default) | multidimensional, logical or numeric array containing zeros and ones
Neighborhood, specified as a multidimensional, logical or numeric array
containing zeros and ones.
NHOOD's size must be odd in
rangefilt uses the neighborhood
rangefilt determines the
center element of the neighborhood by
To specify neighborhoods of other shapes, such as a disk, use the
strel function to create a structuring element object
of the desired shape. Then, extract the neighborhood from the structuring
J— Filtered image
Filtered image, returned as a numeric array, the same size and class as
the input image
I, except for signed integer data
types. The output class for signed data types is the corresponding unsigned
integer data type. For example, if the class of
int8, then the class of
rangefilt uses the morphological functions
imerode to determine the maximum
and minimum values in the specified neighborhood. Consequently,
rangefilt uses the padding behavior of these morphological