Local range of image



J = rangefilt(I) returns the array J, 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 I.


J = rangefilt(I,nhood) performs range filtering of the input image I where you specify the neighborhood in nhood. nhood is a multidimensional array of zeros and ones where the nonzero elements specify the neighborhood for the range filtering operation.


collapse all

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.

RGB = imread('autumn.tif'); 

Convert the RGB image into a L*a*b* image.

LAB = rgb2lab(RGB);

Perform the range filtering on the LAB image.

rLAB = rangefilt(LAB);

Display the images.


figure, imshow(rLAB(:,:,1),[]);

figure, imshow(rLAB(:,:,2),[]);

figure, imshow(rLAB(:,:,3),[]);

Read an image into the workspace, and display it.

I = imread('circuit.tif');

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);
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.

Input Arguments

collapse all

Image to be filtered, specified as a real, nonsparse, numeric array of any dimension.

Data Types: double | uint8 | uint16 | uint32 | logical

Neighborhood, specified as a multidimensional, logical or numeric array containing zeros and ones. NHOOD's size must be odd in each dimension.

By default, rangefilt uses the neighborhood true(3). rangefilt determines the center element of the neighborhood by floor((size(NHOOD) + 1)/2).

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 element object’s neighborhood property.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Output Arguments

collapse all

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 I is int8, then the class of J is uint8.


rangefilt uses the morphological functions imdilate and imerode to determine the maximum and minimum values in the specified neighborhood. Consequently, rangefilt uses the padding behavior of these morphological functions.

Introduced before R2006a