使用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 + 1;

[rice_arr(c),erode_copy] = cal_rice_num(erode_copy, j, i, count);

end

end

end

disp('米粒的个数')

disp(c);

disp('米粒的大小')

disp(rice_arr);

这里是要调用的函数cal_rice_num();

function [rice_area, imchanged] = cal_rice_num(im, i, j, count)

%CAL_RICE_NUM Calculate the rice grains of the image 'rice.png'

% IM is the logical edge-fillhole-erode image of the 'rice.png'

% I, J is the position of the pixel whose value is 1

im(i,j) = 0;

[rows, columns] = size(im);

% For (i-1, j-1)

if i-1 > 0 && i-1 <= rows

if j-1 > 0 && j-1 <= columns

if im(i-1, j-1) == 1

count = count + 1;

[count, im] = cal_rice_num(im, i-1, j-1, count);

end

end

end

% For (i-1, j)

if i-1 > 0 && i-1 <= rows

if j > 0 && j <= columns

if im(i-1, j) == 1

count = count + 1;

[count, im] = cal_rice_num(im, i-1, j, count);

end

end

end

% For (i-1, j+1)

if i-1 > 0 && i-1 <= rows

if j+1 > 0 && j+1 <= columns

if im(i-1, j+1) == 1

count = count + 1;

[count, im] = cal_rice_num(im, i-1, j+1, count);

end

end

end

% For (i, j-1)

if i > 0 && i <= rows

if j-1 > 0 && j-1 <= columns

if im(i, j-1) == 1

count = count + 1;

[count, im] = cal_rice_num(im, i, j-1, count);

end

end

end

% For (i, j+1)

if i-1 > 0 && i-1 <= rows

if j+1 > 0 && j+1 <= columns

if im(i-1, j+1) == 1

count = count + 1;

[count, im] = cal_rice_num(im, i-1, j+1, count);

end

end

end

% For (i+1, j-1)

if i+1 > 0 && i+1 <= rows

if j-1 > 0 && j-1 <= columns

if im(i+1, j-1) == 1

count = count + 1;

[count, im] = cal_rice_num(im, i+1, j-1, count);

end

end

end

% For(i+1, j)

if i+1 > 0 && i+1 <= rows

if j > 0 && j <= columns

if im(i+1, j) == 1

count = count + 1;

[count, im] = cal_rice_num(im, i+1, j, count);

end

end

end

% For(i+1, j+1)

if i+1 > 0 && i+1 <= rows

if j+1 > 0 && j+1 <= columns

if im(i+1, j+1) == 1

count = count + 1;

[count, im] = cal_rice_num(im, i+1, j+1, count);

end

end

end

rice_area = count;

imchanged = im;

MATLAB递归将数字一个个输出,数米粒个数和每个米粒面积的matlab算法实现(递归)。 | 学步园...相关推荐

  1. 利用matlab数米粒数量,数米粒个数和每个米粒面积的matlab算法实现(递归)。

    使用Matlab软件自带的rice.png图片进行处理. 不知道使用的函数利用help function-name 或者 lookfor function-name 查看 这里是实现的主要代码段 %T ...

  2. 如何用matlab进行部分式展开_高数简单问题:真分式化成部分分式之和题目,MATLAB中对多项式进行部分分式展开。...

    用MATLAB进行部分分式展开 MATLAB有1个命令用于求B(s)/A(s)的部分分式展开式. 设s的有理分式为 式中 (i=)和(j=)的某些值可能为零.在MATLAB的行向量中,num和den分 ...

  3. java输出体重指数_Android开发–身高体重指数(BIM)计算–完成BMI程序 | 学步园...

    /* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名称:修改表达用户界 ...

  4. php求完数,php算法:求完全数 | 学步园

    完全数:如果一个数的所有因数(不包括本身)的和刚好等于这个数自身,那么这个数就叫完全数 求完全数 function get_mul($num) { for($i=1;$i<=$num;$i++) ...

  5. matlab knn,MATLAB K近邻算法 — knnsearch() 函数 | 学步园

    K近邻 IDX = knnsearch(X,Y) finds the nearest neighbor in X for each point in Y. X is an MX-by-N matrix ...

  6. 数米粒个数和测米粒大小

    clear,close all I=imread('Image/mili.bmp'); imshow(I); %%%估计背景图象 background=imopen(I,strel('disk',15 ...

  7. 关于MATLAB实现的数字信号处理(二)

    上一篇:关于MATLAB实现的数字信号处理(一) 下一篇:关于MATLAB实现的数字信号处理(三) 文章目录 上一篇:关于MATLAB实现的数字信号处理(一) 下一篇:关于MATLAB实现的数字信号处 ...

  8. matlab 输出数,matlab入门(变量、数值运算、输出)

    变量 变量命名原则 1.以字母开头 2.后面可以跟 字母.数字和下划线 3.长度不超过 63 个字符 4.区分字母的 大小写 分号和续行符 若不想在屏幕上输出结果,可以在语句最后加分号 如果语句很长, ...

  9. AMNO.6 给出一个不多于5位的整数,要求 1、求出它是几位数 2、分别输出每一位数字 3、按逆序输出各位数字,例如原数为321,应输出123 输入 一个不大于5位的数字

    题目描述 给出一个不多于5位的整数,要求 1.求出它是几位数 2.分别输出每一位数字 3.按逆序输出各位数字,例如原数为321,应输出123 输入 一个不大于5位的数字 输出 三行 第一行 位数 第二 ...

最新文章

  1. java将一个数转成36进制的数_编程实现将一个N进制数转换成M进制数。
  2. 40年产权的商业地产,个人投资者决不能碰
  3. php 浏览器能请求post_PHP解析微视无水印播放地址原理分析
  4. 计算机有哪两种绘图,能被计算机接受的数字图像有哪两种?它们分别由什么构成?...
  5. git连接到github(SSH无密码登陆)
  6. 列表,元组,字典类的常见简单方法
  7. 张近东发致家乐福中国员工内部信:唯有坚持、坚守才能取得更大的成功
  8. PHP代码审计弱类型,[代码审计]php弱类型总结
  9. 知乎问答 | 如何在同一坐标系下绘制多幅图形
  10. 自媒体学习教程 新手怎么开始学习自媒体
  11. tungsten mysql_ETL之Tungsten Replicator
  12. 对比度调整的各种方法(一)
  13. PS中的颜色深度1位8位16位32位的解释
  14. 【编程开发】之 Java 实现邮件发送
  15. 计算机一级考试《MS Office》
  16. 用jq做一个点击图片放大消失
  17. 535. TinyURL 的加密与解密(Medium)
  18. 使用css将彩色图片转换为黑白图片
  19. 山东省计算机考试模拟,山东省高校计算机等级考试VB考试模拟系统使用说明
  20. deepin安装tftp服务器_用PXE网络安装Deepin 20系统的设置:可同时安装多台机器

热门文章

  1. GitHub 上最酷的 8 个简历模板
  2. HDU-4540 威威猫系列故事——打地鼠 (动态规划)
  3. 1327集群_警用集群系统标准MPT-1327信令
  4. Anaconda环境下安装opencv
  5. 视频教程-Unity3D实战入门之第三人称射击游戏(TPS)-Unity3D
  6. 带有 VGA 接口的 FPGA 原型设计
  7. html页面显示dcm文件,dcm格式的影像 怎么把avi转换为dcm格式?
  8. Delphi DeviceIoControl函数
  9. 兄弟连的兄弟来自西安
  10. QT之QLineEdit——实现鼠标点击事件