学习笔记_Matlab图像处理

最近在刷b站的matlab教程 贴一下图像处理2的小作业。
简单但比较inspiring。


数米粒原图
数米粒原图。


pic=imread('rice.png');
bg=imopen(pic,strel('disk',15));
temp=imsubtract(pic,bg);
level=graythresh(temp);
bw=im2bw(temp,level);
subplot(1,3,1);imshow(bw);title('b-w image');hold on;        %???
[label, num]=bwlabel(bw,8);    %??
disp(['the number of grains is',num2str(num)])

%practice:size of grains
for i=1:99
    count(i)=0;
    for j=1:size(label,1)
        for k=1:size(label,2)
            if label(j,k)==i
                count(i)=count(i)+1;
            end
        end
    end
end
subplot(1,3,2);
histogram(count);
title('the size of grains');
hold on;

%practise:painting
green=zeros(256,256);
blue=zeros(256,256);
red=label;
    for j1=1:size(red,1)
        for k=1:size(red,2)
            if red(j,k)==0
                red(j,k)=0;
            else
                red(j,k)=255;
            end
        end
    end

test=cat(3,red,green,blue);
subplot(1,3,3);imshow(test);title('painting');

output:
num=99

这里写图片描述


%%bwlabel误差体现在两粒米重叠处 可根据直方图修正。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值