Finds limits to contrast stretch an image
LOW_HIGH=stretchlim(I,TOL)
returns a vector LOW_HIGH which contains a pair of intensities which can be used inimadjust
to stretch the contrast of an image, first of them will be lower value (imadjust
would assign 0 to it) and second is the upper bound. TOL specifies the fraction of the image to saturate at lower and upper limits. It can be a vector of length 2:[LOW_FRACT, HIGH_FRACT]
, or it can be a scalar, in that case[LOW_FRACT, HIGH_FRACT]=[TOL, 1-TOL]
.TOL can't be larger than 0.50 and for TOL=0 then
LOW_HIGH=[min(I(:)), max(I(:))]
.
LOW_HIGH=stretchlim(I)
behaves as described but defaults TOL to[0.01, 0.99]
.
LOW_HIGH=stretchlim(RGB,TOL)
returns a 2-by-3 matrix in LOW_HIGH of lower and upper values to saturate for each plane of the RGB image in M-by-N-by-3 array RGB. TOL is a vector or a scalar, as described above, and the same fractions are applied for each plane.
LOW_HIGH=stretchlim(RGB)
uses[0.01, 0.99]
as default value for TOL.Notes:
Values in LOW_HIGH are of type double and comprised between 0 and 1 regardless class of input image.
Compatibility notes:
- int* and uint* types are still not implemented (waiting for support in Octave 2.1.58).
- This function tries to find limits that are nearer to saturate requested interval. So, for instance, if you requested a 5% and it has to choose between discarding a 1% and a 7%, it will choose the later despite being more than requested. This should be test against MATLAB behaviour.
See also: imadjust
The following code
stretchlim([1:100]) # This discards 1% of data from each end, 1 and 100. # So result should be [2;99]
Produces the following output
ans = 2 99