T = adaptthresh(I) computes a locally adaptive threshold that can be used with the imbinarize function to convert an intensity image to a binary image.
The result, T, is a matrix the same size as I containing normalized intensity values in the range [0, 1].
adaptthresh chooses the threshold based on the local mean intensity (first-order statistics) in the neighborhood of each pixel.
T = adaptthresh(I,sensitivity) computes a locally adaptive threshold with sensitivity factor specified by sensitivity. sensitivity is a scalar in the range [0 1] that indicates sensitivity towards thresholding more pixels as foreground.
T = adaptthresh(___,Name,Value) computes a locally adaptive threshold using name-value pairs to control aspects of the thresholding.
Code Generation support: Yes.
MATLAB Function Block support: Yes.
T = adaptthresh(I) T = adaptthresh(I,sensitivity) T = adaptthresh(___,Name,Value)
%Find Threshold and Segment Bright Rice Grains from Dark BackgroundOpen %This Example Read image into the workspace. I = imread('rice.png'); %Use adaptthresh to determine threshold to use in binarization operation. T = adaptthresh(I, 0.4); %Convert image to binary image, specifying the threshold value. BW = imbinarize(I,T); %Display the original image with the binary version, side-by-side. figure imshowpair(I, BW, 'montage') %Find Threshold and Segment Dark Text from Bright Background Read image into the workspace. I = imread('printedtext.png'); %Using adaptthresh compute adaptive threshold and display the local threshold image. This represents an estimate of average background illumination. T = adaptthresh(I,0.4,'ForegroundPolarity','dark'); figure imshow(T) %Binarize image using locally adaptive threshold BW = imbinarize(I,T); figure imshow(BW)