Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

stretchlim

Find limits to contrast stretch image

Syntax

Low_High = stretchlim(I)
Low_High = stretchlim(I,Tol)
Low_High = stretchlim(RGB,Tol)
Low_High = stretchlim(gpuarrayI,___)

Description

example

Low_High = stretchlim(I) returns Low_High, a two-element vector of pixel values that specify lower and upper limits that can be used for contrast stretching image I. By default, values in Low_High specify the bottom 1% and the top 1% of all pixel values. The gray values returned can be used by the imadjust function to increase the contrast of an image.

Low_High = stretchlim(I,Tol) returns Low_High, a two-element vector of pixel values that specify lower and upper limits that can be used for contrast stretching image I. where Tol specifies the fraction of the image to saturate at low and high pixel values.

Low_High = stretchlim(RGB,Tol) returns Low_High, a two-element vector of pixel values that specify lower and upper limits that can be used for contrast stretching truecolor image RGB.

Low_High = stretchlim(gpuarrayI,___) performs the operation on a GPU. . This syntax requires the Parallel Computing Toolbox™.

Examples

collapse all

Read grayscale image into the workspace and display it.

I = imread('pout.tif');
figure
imshow(I)

Adjust the contrast in the image using stretchlim to set the limits, and display the result. The example uses the default limits [0.01 0.99], saturating the upper 1% and the lower 1%.

J = imadjust(I,stretchlim(I),[]);
figure
imshow(J)

Read grayscale image, creating a gpuArray.

gpuarrayI = gpuArray(imread('pout.tif'));
figure, imshow(gpuarrayI)

Adjust the contrast in the image using stretchlim to set the limits. Display the result.

gpuarrayJ = imadjust(gpuarrayI,stretchlim(I),[]);
figure, imshow(gpuarrayJ)

Input Arguments

collapse all

Grayscale image, specified as a real, nonsparse, numeric array.

Example: I = imread(‘pout.tif'); lohi = stretchlim(I);

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

Fraction of the image to saturate, specified as a numeric scalar or two-element vector [Low_Fract High_Fract] in the range [0 1].

ValueDescription
ScalarIf Tol is a scalar, Low_Fract = Tol, and High_Fract = 1 - Low_Fract, which saturates equal fractions at low and high pixel values.
0If Tol = 0, Low_High = [min(I(:)); max(I(:))].
DefaultIf you omit the Tol argument, [Low_Fract High_Fract] defaults to [0.01 0.99], saturating 2%.
Too bigIf Tol is too big, such that no pixels would be left after saturating low and high pixel values, stretchlim returns [0 1]

Example: lohi = stretchlim(I,[.02 .80]);

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

Truecolor image, specified as a numeric array.

Example: RGB = imread(‘peppers.png'); lohi = stretchlim(RGB);

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

Input image, specified as a gpuArray.

Output Arguments

collapse all

Lower and upper limits for contrast stretching, returned as a two-element vector of pixel values

Extended Capabilities

Introduced before R2006a

Was this topic helpful?