www.gusucode.com > images 案例代码 matlab源码程序 > images/FindThresholdSegmentBrightGrainsFromDarkBackgroundExample.m

    %% Find Threshold and Segment Bright Rice Grains from Dark Background
%  
%%
% 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')