matlab图像处理小结_第1页
matlab图像处理小结_第2页
matlab图像处理小结_第3页
matlab图像处理小结_第4页
matlab图像处理小结_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

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

文档简介

1. functioncenter,r=solve_circle(pt1,pt2,pt3)2. %Effect:solvethecirclewhichacrosspointspt1,pt2andpt33. %Inputs:4. %pt1,pt2,pt3:x,y5. %center:thecirclecenterx0;y06. %r:theradiusofthecircle7. %Author:Sudongcaiat2012/1/28. A=zeros(2,2);B=zeros(2,1);9. A(1,:),B(1)=circle2line(pt1,pt2);10. A(2,:),B(2)=circle2line(pt2,pt3);11. center=AB;12. r=norm(pt1-center);13. 14. functionA,B=circle2line(pt1,pt2)15. %Effect:cast2circlesequationinto1linearequation:16. %(a-x1)2+(b-y1)2=r2|17. %|=2(x1-x2)a+2(y1-y2)b=(x12+y12)-(y22+y22)18. %(a-x2)2+(b-y2)2=r2|19. %Inputs:20. %pt1,pt2:x1,y1,x2,y221. %Outputs:22. %A:2x1-x2,y1-y223. %B:(x12+y12)-(x22+y22)24. %Author:Sudongcaiat2012/1/225. A=2*(pt1-pt2);26. B=norm(pt1)2-norm(pt2)2;close all;clear;clc; i=imread(rice.png);% imshow(i); background=imopen(i,strel(disk,15); i2=imsubtract(i,background);% figure,imshow(i2); i3=imadjust(i2,stretchlim(i2),0 1);% figure,imshow(i3); level=graythresh(i3); bw=im2bw(i3,level);% figure,imshow(bw); labeled,numobjects=bwlabel(bw,4);graindata=regionprops(labeled,all);close all;clear;clc;i=imread(rice.png);background=imopen(i,strel(disk,15);i2=imsubtract(i,background);i3=imadjust(i2,stretchlim(i2),0 1);level=graythresh(i3);bw=im2bw(i3,level);labeled,numobjects=bwlabel(bw,4);data=regionprops(labeled,all);%2006.6.2close all;clear;clc; i=imread(r.jpg);% figure,imshow(i); imgray=rgb2gray(i); figure,imshow(imgray) background=imopen(imgray,strel(disk,15); i2=imsubtract(imgray,background);% figure,imshow(i2); i3=imadjust(i2,stretchlim(i2),0 1);% figure,imshow(i3); level=graythresh(i3); bw=im2bw(i3,level);% figure,imshow(bw); imnobord=imclearborder(bw,4);% figure,imshow(imnobord); labeled,numobjects=bwlabel(bw,4); rgb_label=label2rgb(labeled,spring,c,shuffle); figure,imshow(rgb_label); graindata=regionprops(labeled,all);hold on;for k=1:numobjectslab=sprintf(%d,k);text(graindata(k).Centroid(1),graindata(k).Centroid(2),lab,Color,k);endhold off;%剔除碎米粒 idxdown=find(graindata.Area graindata(idxdown,:)=;%剔除碎米粒%剔除连接米粒 idxup=find(graindata.Area250); %剔除连接米粒big=ismember(labeled,idxup);figure,imshow(big);lab_big,num_big=bwlabel(big,4);rgb_big=label2rgb(lab_big,spring,c,shuffle);figure,imshow(rgb_big);big_data=regionprops(lab_big,all);hold on;for k=1:num_biglab=sprintf(%d,k);text(big_data(k).Centroid(1),big_data(k).Centroid(2),lab,Color,k);endhold off;% graindata(numup,:)=;%剔除连接米粒%获取完整米粒idxsuit=find(graindata.Area=150&graindata.Area graindata mean(graindata.Area) mean(graindata.Eccentricity) mean(graindata.MajorAxisLength) mean(graindata.MinorAxisLength) mean(graindata.EquivDiameter) figure,hist(graindata.Area,20); figure,hist(graindata.Eccentricity,20); figure,hist(graindata.MajorAxisLength,20); figure,hist(graindata.MinorAxisLength,20); figure,hist(graindata.EquivDiameter,20); data=graindata.Area data=graindata.Centroid data=graindata.BoundingBox data=graindata.SubarrayIdx data=graindata.MajorAxisLength data=graindata.MinorAxisLength data=graindata.Eccentricity data=graindata.Orientation data=graindata.ConvexHull data=graindata.ConvexImage data=graindata.ConvexArea data=graindata.Image data=graindata.FilledImage data=graindata.FilledArea data=graindata.EulerNumber data=graindata.Extrema data=graindata.EquivDiameter data=graindata.Solidity data=graindata.Extent data=graindata.PixelIdxList data=graindata.PixelListArea计算各个连通区域中的象素总数BoundingBox包含相应区域的最小矩形Centroid给出每个区域的质心MajorAxisLength与区域具有相同标准二阶中心矩(又叫标准差)的椭圆的长轴长度MinorAxisLength与区域具有相同标准二阶中心矩的椭圆的短轴长度Eccentricity与区域具有相同标准二阶中心矩的椭圆的离心率Orientation与区域具有相同标准二阶中心矩的椭圆的长轴与x轴的交角Image二值图像,与某区域具有相同大小的逻辑矩阵。FilledImage与上相同,唯一区别是这是个做了填充的逻辑矩阵!本例中和上面的没有区别,只有区域有空洞时才有明显差别。FilledArea是标量,填充区域图像中的on像素个数ConvexHull是p行2列的矩阵,包含某区域的最小凸多边形ConvexImage二值图像,用来画出上述的区域最小凸多边形ConvexArea是标量,填充区域凸多边形图像中的on像素个数EulerNumber等于图像中目标个数减去这些目标中空洞的个数Extrema 8行2列矩阵,八方向区域极值点EquivDiameter是标量,等价直径:与区域具有相同面积的圆的直径.计算公式为:sqrt(4*Area/pi)Solidity是标量,同时在区域和其最小凸多边形中的像素比例。计算公式为: Area/ConvexArea,这也是个仿射特征,实际上反映出区域的固靠性程度。Extent是标量,同时在区域和其最小边界矩形中的像素比例。计算公式为:Area除以边界矩形面积,这也是个仿射特征,实际上反映出区域的扩展范围程度。PixelIdxList p元向量,存储区域像素的索引下标PixelList p行ndims(L)列矩阵,存储上述索引对应的像素坐标%基于特定原则的区域选择当你要基于特定准则条件选择某个区域时,将函数ismember和regionprops联合使用是很有用处的。例如:创建一个只包含面积大于80的二值图像,用以下命令idx = find(stats.Area 80);BW2 = ismember(L,idx);regionprops函数的扩展思路在regionprops函数的基础上,你可以使用它提供的基本数据来扩展它的功能,比如我就将区域的曲率数据和骨架数据作为它的另外属性值来开发,从而希望它能用来做更细致的特征提取。%2006.6.2 P221图像粒度测定(雪花) i=imread(snowflakes.png); figure,imshow(i); %(2) clahei=adapthisteq(i,numtiles,10 10); clahei=imadjust(clahei); imshow(clahei); gi=imadjust(im2double(i),0 1); figure,imshow(gi),title(adjusted grayscale image); %(3) se=strel(disk,10); topi=imtophat(gi,se); figure,imshow(topi),title(top-hat image); %(4) for counter=0:22remain=imopen(clahei,strel(disk,counter);intensity_area(counter+1)=sum(remain(:);end figure,plot(intensity_area,m-*),grid on; title(sum of opening (pixels); title(sum of opening values in opened image as a function of radius); xlabel(radius of opening (pixels); ylabel(pixel value sum of opened objects (intensity); for counter=0:20remain=imopen(topi,strel(disk,counter);surfarea(counter+1)=sum(remain(:);end figure,plot(surfarea,m-*),grid on; set(gca,xtick,0 2 4 6 8 10 12 14 16 18 20); title(surface area of opened objects as a function of radius); xlabel(radius of opening (pixels); ylabel(surface area of opened objects (pixels); %(5) intensity_area_prime=diff(intensity_area); figure,plot(intensity_area_prime,m-*),grid on; title(Granulometry(size distrubution) of snowflakes); set(gca,xtick,0 2 4 6 8 10 12 14 16 18 20 22); xlabel(radius of snowflakes(pixels); ylabel(sum of pixel values in snowflakes as a function of radius); derivsurfarea=diff(surfarea); figure,plot(derivsurfarea,m-*),grid on; title(granulometry (size distribution) of stars); xlabel(radius of stars (pixels); ylabel(loss of pixels between two successive openings);%2006.6.2花椒检测clc;clear;close all;i=imread(gj.jpg);imshow(i);icanny=edge(i,canny);imshow(icanny);se90=strel(line,2,90);se0=strel(line,2,0);bwsdil=imdilate(icanny,se90 se0);figure,imshow(bwsdil),title(dilated);ifill=imfill(bwsdil,holes);figure,imshow(ifill);%bwero=imerode(bwsdil,se90 se0);%figure,imshow(bwero);%i2fill=imfill(bwero,holes);%figure,imshow(bwero);%imshow(i2fill);%bwnobord=imclearborder(bwsdil,4);%figure,imshow(bwnobord);bwnobord=imclearborder(ifill,4);figure,imshow(bwnobord);se=strel(disk,5);bwc=imclose(bwnobord,se);bwco=imopen(bwnobord,se);figure,imshow(bwc);figure,imshow(bwco);%mask=bwsdil&bwco;%figure,imshow(mask);clclabeled,numobjects=bwlabel(bwco);numobjectsjdata=regionprops(labeled,all);%jdatajarea=jdata.Area;mean(jarea)max(jarea)min(jarea)hist(jarea,255)jdata.Eccentricity%std(jdata.Eccentricity)/(Mean(jdata.Eccentricity)jstd=std(jdata.Eccentricity)jmean=Mean(jdata.Eccentricity)jcv=jstd/jmean std(jdata.Area)/ mean(jdata.Area) %面积的变异系数 std(jdata.Eccentricity)/ mean(jdata.Eccentricity)%椭圆的变异系数 std(jdata.MajorAxisLength)/ mean(jdata.MajorAxisLength) std(jdata.MinorAxisLength)/ mean(jdata.MinorAxisLength) std(jdata.EquivDiameter)/ mean(jdata.EquivDiameter)%2006.06.06 rice.pngclose all;clear;clc i=imread(rice.png);imshow(i);background=imopen(i,strel(disk,15);figure,imshow(background);i2=imsubtract(i,background);figure,imshow(i2);i3=imadjust(i2,stretchlim(i2),0 1);figure,imshow(i3);level=graythresh(i3);bw=im2bw(i3,level);figure,imshow(bw);imnobord=imclearborder(bw);label,numobjects=bwlabel(imnobord,4);numobjectsrgb_label=label2rgb(label,spring,c,shuffle);figure,imshow(rgb_label);graindata=regionprops(label,all);graindata numdown=find(graindata.Area graindata(numdown,:)=; numup=find(graindata.Area250); graindata(numup,:)=; graindata std(graindata.Area)/ mean(graindata.Area) %面积的变异系数 std(graindata.Eccentricity)/ mean(graindata.Eccentricity)%椭圆的变异系数 std(graindata.MajorAxisLength)/ mean(graindata.MajorAxisLength) std(graindata.MinorAxisLength)/ mean(graindata.MinorAxisLength) std(graindata.EquivDiameter)/ mean(graindata.EquivDiameter)%2006.06.06 rice的垩白度检测 clear;close all;clc; rgb=imread(r.jpg); close all; imshow(rgb); i=rgb2gray(rgb); j=medfilt2(i,5 5); figure,imshow(i); figure,imshow(j); imhist(j,256); t=0.3; v=imadjust(j,t 1,1); imhist(v,256); t_c=0.6; bw_v=im2bw(v,0.01); chalk=imadjust(v,t_c 1,1); bw_chalk=im2bw(chalk,0.01); figure,imshow(v); figure,imshow(bw_v); figure,imshow(chalk); figure,imshow(bw_chalk); degree_chalkness=bwarea(bw_chalk)/bwarea(bw_v)*100 bw=im2bw(j,t); figure,imshow(bw); se=(ones(3,3); bw1=imerode(bw,se); %两次腐蚀 figure,imshow(bw1); bw2=imerode(bw1,se); figure,imshow(bw2); l,num=bwlabel(bw2); %标记腐蚀后的大米图像 t_chalk=100; %设置垩白面积的下限 compare=(l)&(chalkt_chalk);% compare=(bw2)&(bw_chalkt_chalk); r,c=find(compare); %标记垩白米粒的位置 result=bwselect(l,c,r); %显示只含有垩白米粒的图像 figure,imshow(result); l_chalk,num_chalk=bwlabel(result); %标记垩白米粒图像,便于计数 rate_chalky_grains=num_chalk/num*100; rate_chalky_grains%2006.6.17 bwmorph函数 help bwmorphBWMORPH Perform morphological operations on binary image. BW2 = BWMORPH(BW1,OPERATION) applies a specific morphological operation to the binary image BW1. BW2 = BWMORPH(BW1,OPERATION,N) applies the operation N times. N can be Inf, in which case the operation is repeated until the image no longer changes. OPERATION is a string that can have one of these values: bothat Subtract the input image from its closing bridge Bridge previously unconnected pixels clean Remove isolated pixels (1s surrounded by 0s) close Perform binary closure (dilation followed by erosion) diag Diagonal fill to eliminate 8-connectivity of background dilate Perform dilation using the structuring element ones(3) erode Perform erosion using the structuring element ones(3) fill Fill isolated interior pixels (0s surrounded by 1s) hbreak Remove H-connected pixels majority Set a pixel to 1 if five or more pixels in its 3-by-3 neighborhood are 1s open Perform binary opening (erosion followed by dilation) remove Set a pixel to 0 if its 4-connected neighbors are all 1s, thus leaving only boundary pixels shrink With N = Inf, shrink objects to points; shrink objects with holes to connected rings skel With N = Inf, remove pixels on the boundaries of objects without allowing objects to break apart spur Remove end points of lines without removing small objects completely. thicken With N = Inf, thicken objects by adding pixels to the exterior of objects without connected previously unconnected objects thin With N = Inf, remove pixels so that an object without holes shrinks to a minimally connected stroke, and an object with holes shrinks to a ring halfway between the hold and outer boundary tophat Subtract the opening from the input image Class Support - The input image BW1 can be numeric or logical. It must be 2-D, real and nonsparse. The output image BW2 is logical. Examples - BW1 = imread(circles.png); imview(BW1) BW2 = bwmorph(BW1,remove); BW3 = bwmorph(BW1,skel,Inf); imview(BW2) imview(BW3) See also erode, dilate, bweuler, bwperim. Reference page in Help browser doc bwmorphBW1 = imread(circles.png);figure,imshow(BW1)BW2 = bwmorph(BW1,erode);figure,imshow(BW2)%边界提取b=bwmorph(bw,remove);b=bwperim(bw,8); %又叫边界象素测定b=edge(bw,canny); %又叫边界提取%去除孤立象素点nosinglepixel=bwmorph(bw,clean);%去除小面积物体nosmall=bwareaopen(bw,CNN);%阈值处理再取反bw=im2bw(i,graythresh(i);%开运算(消除小物体)与闭运算(填充物体内细小空洞)se=strel(disk,6);iopen=imopen(bw,se);iclose=imclose(bw,se);%腐蚀与膨胀联合操作%(1)创建结构元素se=strel(rectangle,40 30);%(2)使用结构元素腐蚀图像bw1=imread(circbw.tif);bw2=imerode(bw1,se);imshow(bw2);%(3)逆操作,回复矩形原来大小bw3=imdilate(bw2,se);figure,imshow(bw3);%2006.6.18花椒子%直接对灰度图进行canny运算 i=imread(nut.bmp); figure,imshow(i); ig=rgb2gray(i); figure,imshow(ig);%igcanny=edge(ig,canny);%igcfill=imfill(igcanny,hole);igcanny_thresh=edge(ig,canny,(graythresh(ig)*.1);igcfill=imfill(igcanny_thresh,hole); figure,imshow(igcfill);%先对灰度图滤波,再进行canny运算 imed=medfilt2(ig); %中值滤波后对图像边界有一定的损伤! imedcanny=edge(imed,canny); imedfill=imfill(imedcanny,hole); figure,imshow(imedfill); nosmall=bwareaopen(imedfill,150); figure,imshow(nosmall);%注意:若对灰度图像先拉氏锐化,在canny提取边界,效果不大好!%结论:无需拉氏锐化,也不必中值滤波,可直接canny提取边界! ifill=igcfill|imedfill; figure,imshow(ifill); nosmall=bwareaopen(ifill,150); figure,imshow(nosmall);%当t=0.55时,阈值处理再canny运算的效果 imhist(ig); t=0.55; v=imadjust(ig,0 t,1); vcanny=edge(v,canny); vfill=imfill(vcanny,hole); figure,imshow(vfill); ifill=igcfill|vfill; figure,imshow(ifill); nosmall=bwareaopen(ifill,150); figure,imshow(nosmall);%当t=0.6时,阈值处理再canny运算的效果的效果 t=0.6; v=imadjust(ig,0 t,1); vcanny=edge(v,canny); vfill=imfill(vcanny,hole); figure,imshow(vfill); ifill=igcfill|vfill; figure,imshow(ifill); nosmall=bwareaopen(ifill,150); figure,imshow(nosmall);%处理花椒子 i=imread(nut.bmp);%figure,imshow(i);ig=rgb2gray(i);figure,imshow(ig); imed=medfilt2(ig);imedcanny=edge(imed,canny);imedfill=imfill(imedcanny,hole);%figure,imshow(imedfill);nosmall=bwareaopen(imedfill,150); figure,imshow(nosmall); labeled,numobjects=bwlabel(nosmall,4); rgb_label=label2rgb(labeled,spring,c,shuffle);% figure,imshow(rgb_label); nutdata=regionprops(labeled,all); min(nutdata.Solidity) rectangle(Position, 253.5000 207.5000 26.0000 28.0000) %画矩形 rectangle(Position, 250.5000 50.5000 27.0000 26.0000) figure,imshow(nutdata(1).Image) %只显示1号物体的图像 figure,imshow(nutdata(1).ConvexImage) %画出1号物体的凸多边形 std(nutdata.Eccentricity)/ mean(nutdata.Eccentricity)std(nutdata.Area)/ mean(nutdata.Area)std(nutdata.Solidity)/ mean(nutdata.Solidity) std(nutdata.Centroid)/ mean(nutdata.Centroid)std(nutdata.MajorAxisLength)/ mean(nutdata.MajorAxisLength)std(nutdata.MinorAxisLength)/ mean(nutdata.MinorAxisLength)std(nutdata.Orientation)/ mean(nutdata.Orientation)std(nutdata.EquivDiameter)/ mean(nutdata.EquivDiameter)std(nutdata.Extent)/ mean(nutdata.Extent)std(nutdata.Extrema)/ mean(nutdata.Extrema)%处理花椒皮close all;clc;clear; i=imread(p.bmp);imshow(i);ig=rgb2gray(i);figure,imshow(ig);imed=medfilt2(ig);imedcanny=edge(imed,canny);figure,imshow(imedcanny); se

温馨提示

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

评论

0/150

提交评论