Main Content

rangefilt

Local range of image

Description

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.

example

J = rangefilt(I,nhood) returns the local range of image I using the specified neighborhood, nhood.

example

Examples

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.

imshowpair(I,J,'montage')

Figure contains an axes object. The hidden axes object contains an object of type image.

This example shows how to detect regions of texture in an image using the texture filter functions

Read an image into the workspace and display it. In the figure, the background is smooth—there is very little variation in the gray-level values. In the foreground, the surface contours of the coins exhibit more texture. In this image, foreground pixels have more variability and thus higher range values.

I = imread('eight.tif');
imshow(I)

Figure contains an axes object. The hidden axes object contains an object of type image.

Filter the image with the rangefilt function and display the results. Range filtering makes the edges and contours of the coins visible.

K = rangefilt(I);
figure
imshow(K)

Figure contains an axes object. The hidden axes object contains an object of type image.

Read an image into the workspace, and display it.

I = imread('circuit.tif');
imshow(I);

Figure contains an axes object. The hidden axes object contains an object of type image.

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

Figure contains an axes object. The hidden axes object with title Range filtering using specified neighborhood (left) and default neighborhood (right) contains an object of type image.

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 numeric array of any dimension.

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

Neighborhood, specified as a logical or numeric array containing zeros and ones. The size of nhood must be odd in each dimension. 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 of the same size as the input image I.

If I is of data type double, single, or an unsigned data type such as uint8, then the data type of J is the same as the data type of I. If I is int8, int16, or int32, then the data type of J is uint8, uint16, or uint32, respectively.

Data Types: single | doubl | uint8 | uint16 | uint32

Algorithms

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.

Extended Capabilities

Version History

Introduced before R2006a

expand all