数米粒个数和每个米粒面积的matlab算法实现(递归)。
来源:互联网 发布:永久禁止程序访问网络 编辑:程序博客网 时间:2024/05/01 08:33
使用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 erodeerode_copy = erode;imtool(erode_copy);% c is the number of the rice grainsc = 0;% rice_arr is an array which stores the area of each rice grainrice_arr = zeros(1, 100);%% Calculate the number of the rice and the area of each rice graincount = 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 endenddisp('米粒的个数')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 endend% 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 endend% 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 endend% 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 endend% 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 endend% 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 endend% 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 endend% 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 endendrice_area = count;imchanged = im;
- 数米粒个数和每个米粒面积的matlab算法实现(递归)。
- 不用递归的方法计算米粒的个数和每个米粒的面积,matlab实现
- 数米粒个数和测米粒大小
- 利用MATLAB数米粒数量
- VS+++opencv++MFC++数米粒【计算联通区域的个数及联通区域内像素的个数】
- VS+++opencv++MFC++数米粒【计算联通区域的个数及联通区域内像素的个数】
- 国王输棋求米粒的问题!(java)
- opencv入门之数米粒
- 米粒和国际象棋棋盘问题
- 高级图像处理初步(大米粒的处理)
- OpenCV统计米粒数目-计算联通区域的个数及联通区域内像素的个数
- OpenCV统计米粒数目-计算联通区域的个数及联通区域内像素的个数
- OpenCV统计米粒数目-计算联通区域的个数及联通区域内像素的个数
- 大数运算经典:棋盘上的米粒。
- 【数字图像处理】求图像rice.png中米粒个数
- python pyqt4 qtwekit 实现百度自动登录领米粒
- 鲜血中竟然可以看到无数米粒大小的冰块
- 小米粒儿的CSDN博客开启啦~~
- 使用hibernate插入数据的例子
- Android平台竞争引爆价格战
- xcode 4.0.2破解,实现真机调试
- AlarmManager2
- 3D技术:提供真实可触的虚拟境界,激起新一轮的网络经济变革
- 数米粒个数和每个米粒面积的matlab算法实现(递归)。
- 互联网产品交互设计体验的前世今生
- 互联网开放与垄断的辩证关系
- Why are Objective-C delegates usually given the property assign instead of retain?
- 新浪“微币”加入“货币战争” 虚拟货币谁贬值
- 嵌入式系统概括
- kthread_create和kernel_thread的区别和总结
- c语言五大排序算法
- arm-linux-gcc-3.4.1交叉编译器在redhat9.0下的安装(VMware)