Ai
1 Star 0 Fork 0

Vincent/MATLAB_Study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
lesson09.m 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
VINCENT 提交于 2022-10-22 17:59 +08:00 . MATLAB学习
%%
%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);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/Vincentstudy/MATLAB_Study.git
git@gitee.com:Vincentstudy/MATLAB_Study.git
Vincentstudy
MATLAB_Study
MATLAB_Study
master

搜索帮助