matlab之影像处理(下)

【参看:https://www.bilibili.com/video/av14503445/?p=9

目录

影像变为黑白影像:

graythresh()和im2bw()

预测背景

计算一共有多少米:

bwlabel()

用颜色标注:label2rgb()

regionprops()


影像变为黑白影像:

 

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);

【可以选择要显示的米粒。】

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值