【参看:https://www.bilibili.com/video/av14503445/?p=9】
目录
影像变为黑白影像:
graythresh()和im2bw()
I = imread('rice.png');
level=graythresh(I);
bw =im2bw(I,level); subplot(1,2,1); imshow(I);
subplot(1,2,2); imshow(bw);


预测背景

>> BG =imopen(I,strel('disk',15));
>> imshow(BG);
>>



I = imread('rice.png'); level = graythresh(I);
bw = im2bw(I,level); subplot(1,2,1);
imshow(bw); BG = imopen(I,strel('disk',15));
I2 = imsubtract(I,BG); level = graythresh(I2);
bw2 = im2bw(I2,level);
subplot(1,2,2); imshow(bw2);

计算一共有多少米:



bwlabel()
>> I = imread('rice.png');
>> BG =imopen(I,strel('disk',15));
>> I2 = imsubtract(I,BG); level = graythresh(I2);
>> BW = im2bw(I2,level);
>> [labeled, numObjects] = bwlabel(BW,8);
>> numObjects
numObjects =
99
>>

【99粒米】
用颜色标注:label2rgb()

>> I = imread('rice.png');
>> BG =imopen(I,strel('disk',15));
>> I2 = imsubtract(I,BG); level = graythresh(I2);
>> BW = im2bw(I2,level);
>> [labeled, numObjects] = bwlabel(BW,8);
>> RGB_label = label2rgb(labeled);imshow(RGB_label);

regionprops()
得到图片的一些特性:
>> I = imread('rice.png');
>> BG =imopen(I,strel('disk',15));
>> I2 = imsubtract(I,BG); level = graythresh(I2);
>> BW = im2bw(I2,level);
>> [labeled, numObjects] = bwlabel(BW,8);
>> graindata = regionprops(labeled,'basic');
>> graindata(51)
ans =
Area: 155
Centroid: [112.4258 245.8645]
BoundingBox: [108.5000 234.5000 8 22]
>>

>> I = imread('rice.png');
>> level = graythresh(I);
>> BG =imopen(I,strel('disk',15));
>> I2 = imsubtract(I,BG);
>> BW = im2bw(I2,graythresh(I2));
>> ObjI = bwselect(BW); imshow(ObjI);
【可以选择要显示的米粒。】
本文深入探讨了图像处理的关键技术,包括灰度转换、背景预测、对象计数、颜色标注及区域属性获取。通过MATLAB函数如graythresh(), im2bw(), bwlabel(), label2rgb() 和 regionprops() 的应用实例,详细解释了如何从原始图像中提取和分析有用信息。

4014

被折叠的 条评论
为什么被折叠?



