基于MATLAB的图像处理方法进行面积计算.doc_第1页
基于MATLAB的图像处理方法进行面积计算.doc_第2页
基于MATLAB的图像处理方法进行面积计算.doc_第3页
基于MATLAB的图像处理方法进行面积计算.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

% Edit By :DTL%图片颜色均衡x_min=58;x_max=1439;y_min=1;y_max=853;valid_pix_cnt=0;%浅色区域像素点个数计数%原始图像I=imread(ini_p2.png);figure(1)imshow(I);sum_pix=(x_max-x_min+1)*(y_max-y_min+1);mean_R=sum(sum(I(y_min:y_max,x_min:x_max,1)/sum_pix;mean_G=sum(sum(I(y_min:y_max,x_min:x_max,2)/sum_pix;mean_B=sum(sum(I(y_min:y_max,x_min:x_max,3)/sum_pix;I(249:370,423:595,1)=mean_R-5;I(249:370,423:595,2)=mean_G-5;I(249:370,423:595,3)=mean_B-5;%分块均衡Lx=150;Ly=100;blk_pix=Lx*Ly;x_inc=15;y_inc=9;x_cnt=floor(x_max-x_min-Lx+1)/x_inc)+1;y_cnt=floor(y_max-y_min-Ly+1)/y_inc)+1;I_blc=I;%均衡处理for x_blc=0:x_cnt for y_blc=0:y_cnt x_start=x_min+x_blc*x_inc; x_end=x_min+x_blc*x_inc+Lx-1; if(x_end=x_max) x_start=x_max-Lx+1; x_end=x_max;end y_start=y_min+y_blc*y_inc;y_end=y_min+y_blc*y_inc+Ly-1; if(y_end=y_max) y_start=y_max-Ly+1; y_end=y_max;end blk_mean_R=sum(sum(I(y_start:y_end,x_start:x_end,1)/blk_pix; blk_mean_G=sum(sum(I(y_start:y_end,x_start:x_end,2)/blk_pix; blk_mean_B=sum(sum(I(y_start:y_end,x_start:x_end,3)/blk_pix; I_blc(y_start:y_end,x_start:x_end,1)=I(y_start:y_end,x_start:x_end,1)*(mean_R/blk_mean_R); I_blc(y_start:y_end,x_start:x_end,2)=I(y_start:y_end,x_start:x_end,2)*(mean_G/blk_mean_G); I_blc(y_start:y_end,x_start:x_end,3)=I(y_start:y_end,x_start:x_end,3)*(mean_B/blk_mean_B); endendfigure(2)imshow(I_blc);title(均衡处理(Lx= num2str(Lx) ;Ly= num2str(Ly) ;x_inc= num2str(x_inc) ;y_inc= num2str(y_inc) ;);%I_ext=I_blc;%阈值设定ThR1=190;ThG1=128;ThB1=128;x_start1=x_min;x_end1=x_max;y_start1=y_min;y_end1=y_max;%处理区域1for y=x_start1:x_end1 for x=y_start1:y_end1 if(I_blc(x,y,1)ThR1 & I_blc(x,y,2)ThG1 & I_blc(x,y,3)ThB1) I_ext(x,y,1)=0;I_ext(x,y,2)=255;I_ext(x,y,3)=0; end endendfigure(7)imshow(I_ext)%去除零散点cnt=0;I_ext2=I_ext;for y=x_start1+1:x_end1-1 for x=y_start1+1:y_end1-1 if(I_ext(x,y,1)=0&I_ext(x,y,2)=255&I_ext(x,y,3)=0) cnt=cnt+1;end if(I_ext(x+1,y,1)=0&I_ext(x+1,y,2)=255&I_ext(x+1,y,3)=0) cnt=cnt+1;end if(I_ext(x,y+1,1)=0&I_ext(x,y+1,2)=255&I_ext(x,y+1,3)=0) cnt=cnt+1;end if(I_ext(x+1,y+1,1)=0&I_ext(x+1,y+1,2)=255&I_ext(x+1,y+1,3)=0) cnt=cnt+1;end if(I_ext(x-1,y,1)=0&I_ext(x-1,y,2)=255&I_ext(x-1,y,3)=0) cnt=cnt+1;end if(I_ext(x,y-1,1)=0&I_ext(x,y-1,2)=255&I_ext(x,y-1,3)=0) cnt=cnt+1;end if(I_ext(x-1,y-1,1)=0&I_ext(x-1,y-1,2)=255&I_ext(x-1,y-1,3)=0) cnt=cnt+1;end if(I_ext(x-1,y+1,1)=0&I_ext(x-1,y+1,2)=255&I_ext(x-1,y+1,3)=0) cnt=cnt+1;end if(I_ext(x+1,y-1,1)=0&I_ext(x+1,y-1,2)=255&I_ext(x+1,y-1,3)=0) cnt=cnt+1;end if(cnt4) I_ext2(x,y,1)=0;I_ext2(x,y,2)=255;I_ext2(x,y,3)=0; valid_pix_cnt=valid_pix_cnt+1; else I_ext2(x,y,1)=I(x,y,1);I_ext2(x,y,2)=I(x,y,2);I_ext2(x,y,3)=I(x,y,3);end cnt=0; endend%浅色区域面积占总面积的百分比rate=valid_pix_cnt/sum_pixfigure(8) ;imshow(I_ext2);title(阈值(ThR1= num2str(ThR1) ,ThG1= . num2str(ThG1) ,ThB1= num2str(ThB1) ),提取结果,浅色区域比率: num2str(rate) );ThR1=190;ThG1=128;ThB1=128;xlab

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论