数米粒个数和每个米粒面积的matlab算法实现(递归)。

本文介绍了如何使用Matlab处理rice.png图片,通过递归算法来数米粒数量并计算每个米粒的面积。通过查阅帮助文档或lookfor命令寻找相关函数辅助实现。
摘要由CSDN通过智能技术生成

使用Matlab软件自带的rice.png图片进行处理。 不知道使用的函数利用help function-name 或者 lookfor function-name 查看

这里是实现的主要代码段

%The procedure below is to calculate the number of rice in the image
%'rice.png';
rice = imread('rice.png');
ed = edge(rice, 'canny');
fillhole = imfill(ed, 'hole');
se = strel('disk', 3);
%   erode is the processed image of 'rice.png'
erode = imopen(fillhole, se);
figure, imshow(erode);
%   imtool(erode);
%   erode_copy is the copy of erode
erode_copy = erode;
imtool(erode_copy);
%   c is the number of the rice grains
c = 0;
%   rice_arr is an array which stores the area of each rice grain
rice_arr = zeros(1, 100);
%% Calculate the number of the rice and the area of each rice grain
count = 0;
flagarr = zeros(256);
for i = 1:256
    for j = 1:256
        flag = erode_copy(j, i);
        if flag == 1
            c = c + 
  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值