学生联盟网为您提供优质参考范文! 体会工作报告法律咨询精彩演讲各类材料
当前位置: 学生联盟网 > 公文写作 > 法律咨询 > 数字图像处理代码大全

数字图像处理代码大全

时间:2021-09-30 13:19:27 来源:学生联盟网

1.图像反转MATLAB程序实现如下匸imreadxia n.bmp;Jdoublel;J-J256-1;Hui nt8J;subplot1,2,1,imshowl; subplot1,2,2,imshowH;2.灰度线性变换MATLAB程序实现如下Iimreadxia n.bmp;subplot2,2,1,imshowI; title原始图像;axis50,250,50,200;axis on;I1 rgb2grayl;subplot2,2,2,imshowI1; title灰度图像;axis50,250,50,200;axis on;Jimadjustl1,0.1 0.5,; 为0 1图像反转线性变换显示坐标系显示坐标系局部拉伸,把0.1 0.5内的灰度拉伸subplot2,2,3,imshowJ; title线性变换图像0.1 0.5; axis50,250,50,200;grid on;显示网格线axis on;显示坐标系Kimadjustl1,0.3 0.7,; 局部拉伸,把0.3 0.7内的灰度拉 伸为0 1subplot2,2,4,imshowK;title线性变换图像0.3 0.7;axis50,250,50,200;grid on;显示网格线axis on;显示坐标系3.非线性变换MATLAB程序实现如下Iimreadxia n.bmp;I1 rgb2grayl; subplot1,2,1,imshowI1; title灰度图像;axis50,250,50,200;grid on;显示网格线axis on;显示坐标系JdoubleI1;J40*logJ1;Hui nt8J;subplot1,2,2,imshowH; title对数变换图像;显示网格线显示坐标系axis50,250,50,200;grid on;axis on;4.直方图均衡化MATLAB程序实现如下Iimreadxia n.bmp;Irgb2grayI;figure;subplot2,2,1;imshowI;subplot2,2,2;imhistI;I仁 histeq I;figure;subplot2,2,1;imshowI1;subplot2,2,2;imhistI1;5.线性平滑滤波器用MATLAB实现领域平均法抑制噪声程序 匸imreadxia n.bmp;subplot231imshowltitle原始图像Irgb2grayI;I1im noisel,salt subplot232imshowI1进行3*3模进行5*5模波进行7*7模进行9*9模title添加椒盐噪声的图像k1filter2fspecialaverage,3,l1/255;板平滑滤波k2filter2fspecialaverage,5,l1/255;k3filter2fspecialaverage,7,l1/255;板平滑滤波k4filter2fspecialaverage,9,l1/255;板平滑滤波模板平滑滤波;模板平滑滤波;模板平滑滤波;subplot233,imshowk1;title3*3subplot234,imshowk2;title5*5subplot235,imshowk3;title7*7subplot236,imshowk4;title9*9模板平滑滤波;6中值滤波器用MATLAB实现中值滤波程序如下 匸imreadxia n.bmp;匸rgb2grayl;Jimno isel,salt subplot231,imshowI;title原图像; subplot232,imshowJ;title添加椒盐噪声图像;k1medfilt2J;进行3*3模板中值滤波k2medfilt2J,5,5;进行5*5模板中值滤波k3medfilt2J,7,7;进行7*7模板中值滤波k4medfilt2J,9,9;进行9*9模板中值滤波subplot233,imshowk1;title3*3模板中值滤波;subplot234,imshowk2;title5*5模板中值滤波;subplot235,imshowk3;title7*7模板中值滤波;subplot236,imshowk4;title9*9模板中值滤波;7.用Sobel算子和拉普拉斯对图像锐化Iimreadxia n.bmp;subplot2,2,1,imshowI;title原始图像;axis50,250,50,200;grid on;axis on;I仁im2bwl;显示网格线显示坐标系subplot2,2,2,imshowl1; title二值图像;axis50,250,50,200;grid on;axis on;Hfspecialsobe l;Jfilter2H,l1; subplot2,2,3,imshowJ; titlesobel算子锐化图像 axis50,250,50,200;grid on;axis on;h0 1 0,1 -4 1,0 1 0;J1co nv2l1,h,same;显示网格线显示坐标系选择sobel算子卷积运算;显示网格线显示坐标系拉普拉斯算子卷积运算subplot2,2,4,imshowJ1;title拉普拉斯算子锐化图像;axis50,250,50,200;grid on;显示网格线axis on;显示坐标系8.梯度算子检测边缘用MATLAB实现如下匸imreadxia n.bmp;subplot2,3,1;imshowl;title(原始图像);axis50,250,50,200;grid on;显示网格线axis on;显示坐标系I1im2bw I;subplot2,3,2;imshowI1;title(二值图像);axis50,250,50,200;grid on;显示网格线axis on;显示坐标系I2edgeI1,roberts;figure;subplot2,3,3;imshowI2;title(roberts算子分割结果;axis50,250,50,200;grid on;显示网格线axis on;显示坐标系I3edgel1,sobel;subplot2,3,4;imshowl3;title(sobel算子分割结果);axis50,250,50,200;grid on;显示网格线axis on;显示坐标系l4edgel1,Prewitt;subplot2,3,5;imshowI4;title(Prewitt算子分割结果;axis50,250,50,200;grid on;显示网格线axis on;显示坐标系9.LOG算子检测边缘用MATLAB程序实现如下Iimreadxia n.bmp;subplot2,2,1;imshowI;title(原始图像);11 rgb2grayl; subplot2,2,2; imshowll;title灰度图像;I2edgel1,log; subplot2,2,3;imshowI2; titlelog算子分割结果;1O.Canny算子检测边缘用MATLAB程序实现如下limreadxia n.bmp; subplot2,2,1;imshowI;title原始图像I1 rgb2grayI;subplot2,2,2;imshowI1;title灰度图像;I2edgeI1,ca nn y;subplot2,2,3;imshowI2;titlecanny算子分割结果;将彩色图像转化灰度图像计算将灰度图像转化为二将灰度图像转化为二值图计算起始点列坐标计算起始点行坐标11.边界跟踪bwtraceboundary 函数clc clear all匸imreadxia n.bmp;figureimshowI;title原始图像;11 rgb2grayl;thresholdgraythreshl1;值图像所需的门限BWim2bwl1,threshold; 像figureimshowBW;title二值图像; dimsizeBW;colro un ddim2/2-90; rowfi ndBW,col,1;conn ectivity8;nu m_po in ts180;con tourbwtracebo un daryBW,row,col,N,c onn ectivity,num_p oin ts;提取边界 figureimshowll;hold on;plotcontour,2,contour,1,g,LineWidth ,2; title边界跟踪图像;12.Hough 变换I imreadxia n.bmp;rotlrgb2grayl;subplot2,2,1;imshowrotI;title灰度图像;axis50,250,50,200;grid on;axis on;BWedgerotI,prewitt;subplot2,2,2;imshowBW;titleprewitt算子边缘检测后图像;axis50,250,50,200;grid on;axis on;H,T,RhoughBW;subplot2,2,3;imshowH,,XData,T ,YData,R,lnitialMagnification,fit; title霍夫变换图;xlabeltheta,ylabelrho;axis on ,axis no rmal,hold on;PhoughpeaksH,5,threshold,ceil0.3*maxH;xTP,2;yRP,1;plotx,y,s,color,white;lineshoughlinesBW,T,R,P ,FillGap,5,MinLength,7;subplot2,2,4;,imshowrotI;title霍夫变换图像检测;axis50,250,50,200;grid on;axis on;hold on;max_le n0;for k1le ngthli nesxyli nesk.poi nt1;li nesk.poi nt2;plotxy,1,xy,2,Li neWidth,2,Color,gree n;plotxy1,1,xy1,2,x,Li neWidth,2,Color,yellow;plotxy2,1,xy2,2,x,Li neWidth,2,Color,red;Ienn ormli nesk.poi nt1-li nesk.poi nt2;ifle n max_le nmax_le nle n;xyon gxy;endendplotxy_lo ng,1,xy_lo ng,2,L in eWidth,2,Color,cya n;13.直方图阈值法用MATLAB实现直方图阈值法Iimreadxia n.bmp;11 rgb2grayI;figure;subplot2,2,1;imshowl1;title灰度图像axis50,250,50,200;grid on;显示网格线axis on; 显示坐标系测量图像尺寸预创建存放m,nsizel1;参数GPzeros1,256;灰度出现概率的向量for k0255计算每级灰度出现的概率,将其存入 GP中相应位置endsubplot2,2,2,bar0255,GP,g方图title(灰度直方图)xlabel灰度值ylabel(出现概率)I2im2bwI,150/255;subplot2,2,3,imshowI2;title(阈值150的分割图像)axis50,250,50,200;grid on;显示网格线axis on;显示坐标系l3im2bwl,200/255;GPk1le ngthfi ndl1k/m* n;绘制直subplot2,2,4,imshowI3;title(阈值200的分割图像)axis50,250,50,200;grid on;显示网格线axis on;显示坐标系14.自动阈值法Otsu法用MATLAB实现Otsu算法clc clear all匸imreadxia n.bmp;subplot1,2,1,imshowl;title原始图像axis50,250,50,200;grid on;axis on;levelgraythreshl;BWim2bwl,level;显示网格线显示坐标系确定灰度阈值subplot1,2,2,imshowBW;titleOtsu法阈值分割图像axis50,250,50,200;grid on;axis on;显示网格线显示坐标系15.膨胀操作Iimreadxia n.bmp;I1 rgb2grayI; subplot1,2,1; imshowI1;title灰度图像载入图像axis50,250,50,200;grid on;axis on;sestreldisk,1;I2imdilatel1,se;行膨胀subplot1,2,2;imshowl2;title膨胀后图像;axis50,250,50,200;grid on;axis on;16.腐蚀操作MATLAB实现腐蚀操作Iimreadxia n.bmp;I1 rgb2grayI;subplot1,2,1;imshowI1;title灰度图像axis50,250,50,200;grid on;axis on;显示网格线显示坐标系生成圆形结构元素用生成的结构元素对图像进显示网格线显示坐标系载入图像显示网格线显示坐标系sestreldisk,1;生成圆形结构元素用生成的结构元素对图像进行腐显示网格线显示坐标系I2imerodel1,se;蚀subplot1,2,2;imshowl2;title腐蚀后图像;axis50,250,50,200;grid on;axis on;17.开启和闭合操作用MATLAB实现开启和闭合操作Iimreadxia n.bmp; 载入图像subplot2,2,1,imshowI;title原始图像;axis50,250,50,200;axis on;显示坐标系I1 rgb2grayI;subplot2,2,2,imshowI1;title灰度图像;axis50,250,50,200;axis on;显示坐标系sestreldisk,1;采用半径为1的圆作为结构元素I2imope nl1,se;开启操作I3imclosel1,se;闭合操作subplot2,2,3,imshowl2;title(开启运算后图像);axis50,250,50,200;axis on;显示坐标系subplot2,2,4,imshowI3;title(闭合运算后图像);axis50,250,50,200;axis on;显示坐标系18.开启和闭合组合操作Iimreadxia n.bmp;载入图像subplot3,2,1,imshowI;title(原始图像);axis50,250,50,200;axis on;显示坐标系I1 rgb2grayl;subplot3,2,2,imshowI1;title(灰度图像);axis50,250,50,200;axis on;显示坐标系sestreldisk,1;I2imope nl1,se;开启操作I3imclosel1,se;闭合操作subplot3,2,3,imshowl2;title(开启运算后图像);axis50,250,50,200;axis on;显示坐标系subplot3,2,4,imshowI3;title(闭合运算后图像);axis50,250,50,200;axis on;显示坐标系sestreldisk,1;I4imope nl1,se;I5imcloseI4,se;subplot3,2,5,imshowI5;开一闭运算图像title(开一闭运算图像);axis50,250,50,200;axis on;显示坐标系I6imcloseI1,se;I7imope nl6,se;subplot3,2,6,imshowI7;闭一开运算图像title(闭一开运算图像);axis50,250,50,200;axis on;19.形态学边界提取利用MATLAB实现如下Iimreadxia n.bmp; subplot1,3,1,imshowl; title原始图像; axis50,250,50,200; grid on;axis on;I1im2bw I; subplot1,3,2,imshowI1; title二值化图像; axis50,250,50,200; grid on;axis on;I2bwperimI1; subplot1,3,3,imshowI2;title边界周长的二值图像 axis50,250,50,200;grid on;显示坐标系载入图像显示网格线显示坐标系显示网格线显示坐标系获取区域的周长;axis on;20.形态学骨架提取利用MATLAB实现如下匸imreadxia n.bmp; subplot2,2,1,imshowl; title原始图像;axis50,250,50,200; axis on;I1im2bw I; subplot2,2,2,imshowI1; title二值图像;axis50,250,50,200; axis on;I2bwmorphI1,skel,1; subplot2,2,3,imshowI2; title1次骨架提取;axis50,250,50,200; axis on;I3bwmorphI1,skel,2; subplot2,2,4,imshowI3; title2次骨架提取;axis50,250,50,200; axis on;21.直接提取四个顶点坐标I imreadxia n.bmp;I 1,,1;BWim2bw ;figureimshowBWx,ygetpts