Image Thresholding:
>> I=imread('rice.png');imhist(I);
Graythrsh() and im2bw():
>> I=imread('rice.png');imhist(I);
>> level=graythresh(I);
>> bw=im2bw(I,level);
>> subplot(1,2,1);imshow(I);
>> subplot(1,2,2);imshow(bw);
警告: 在停靠的图形中,图像的初始放大倍数设置为 'fit'。
> In imshow (line 289)
Exercise:
I=imread('rice.png');
subplot(1,2,1);
imshow(I);
level=graythresh(I)*255;
K=zeros(size(I));
for i=1:size(I,1)
for j=1:size(I,2)
if I(i,j)>level
K(i,j)=1;
else
K(i,j)=0;
end;
end;
end;
subplot(1,2,2);
imshow(K);
Background Estimation:
>> I=imread('rice.png');
>> BG=imopen(I,strel