07图片分析(2)
Image thresholding 图片二级化,灰阶变黑白
-
imread() imshow()
-
imhist() 用来显示图片的灰阶分布
-
graythresh() 给参数图片计算最佳的阙值
-
im2bw() 将图片转成黑白图片 graylevel -> binary
I = imread('rice.png'); level=graythresh(I); bw=im2bw(I, level); subplot(1,2,1); imshow(I); subplot (1,2,2); imshow(bw);
I = imread('rice.png');
subplot(1,2,1);
imshow(I);
level = graythresh(I)*255;
bw = ones(size(I,1),size(I,2));
for i = 1:size(I,1)
for j = 1:size(I,2)
if I(i,j)>=level
bw(i,j)=1;
else
bw(i,j)=0;
end
end
end
subplot(1,2,2);
imshow(bw);