代码拉取完成,页面将自动刷新
%%
%1求出二进制图像
I = imread('rice.png'); level=graythresh(I);
bw=im2bw(I, level); subplot(1,2,1); imshow(I);
subplot (1,2,2); imshow(bw);
%%
%2将背景提出来
I = imread('rice.png');
BG = imopen(I, strel('disk', 15));
imshow(BG);
%%
%3去除背景
I = imread('rice.png');
subplot(1,3,1); imshow(I);
BG = imopen(I, strel('disk', 15));
subplot(1,3,2); imshow(BG);
I2 = imsubtract(I, BG);
subplot(1,3,3); imshow(I2);
%%
%4(1,3)两张图做比较
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);
%%
%5计算米粒数量
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);
%%
%6把每一颗米用RGB颜色标号
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);
%%
%7求出每科米的大小、位置
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');
%查看第51颗米的大小位置信息
graindata(51)
%%
%8查看选定米粒的影像
%选中后按enter即可
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);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。