您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 数字图像处理指令及效果
数字图象处理1图象读取及彩色图象转化为灰度图象原图灰度变换指令:clearcloseallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\1.jpg');subplot(121),imshow(I);title(‘原图’);L=rgb2gray(I);subplot(122),imshow(L);title(‘灰度变换’)2直方图原图00.511.522.533.544.5x104原图直方图0100200指令:clearcloseallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');subplot(121),imshow(I);title(‘原图’);L=rgb2gray(I)subplot(122),imhist(L);title(‘原图直方图’)3图象旋转指令:clearcloseallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');subplot(121),imshow(I);title(‘原图’);theta=30;K=imrotate(I,theta);subplot(122),imshow(K);title(‘旋转后图’)原图旋转后图4、边缘检测clearcloseallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\1.jpg');subplot(121),imshow(I);bw1=im2bw(I);bw2=double(bw1);J1=edge(I,’sobel’);J2=edge(I,’prewitt’);J3=edge(I,’log’);subplot(1,4,1),imshow(I);subplot(1,4,2),imshow(J1);subplot(1,4,3),imshow(J2);subplot(1,4,4),imshow(J3);5图像反转closeallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');J=double(I);J=-J+(256-1);H=uint8(J);subplot(1,2,1),imshow(I);subplot(1,2,2),imshow(H);6灰度线性变换原始图象500100015002004006008001000灰度图像500100015002004006008001000线性变换图像[0.1,0.5]500100015002004006008001000线性变换图像[0.30.7]500100015002004006008001000closeallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg')subplot(2,2,1),imshow(I);title('原始图像');axison;I1=rgb2gray(I);subplot(2,2,2),imshow(I1);title('灰度图像');axison;J=imadjust(I1,[0.10.5],[]);subplot(2,2,3),imshow(J);title('线性变换图像[0.10.5]');gridonaxisonK=imadjust(I1,[0.30.7],[]);subplot(2,2,4),imshow(K);title('线性变换图像[0.30.7]');gridon;axison7非线性变换原始图象500100015002004006008001000灰度图像500100015002004006008001000对数变换图像500100015002004006008001000closeallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');subplot(2,2,1),imshow(I);title('原始图像')I1=rgb2gray(I);clearsubplot(2,2,2),imshow(I1);title('灰度图像');gridon;axison;J=double(I1);J=40*(log(J+1));H=uint8(J);subplot(2,2,3),imshow(H);title('对数变换图像');gridon;axison;8直方图均衡化灰度图像01234x1040100200024x1040100200closeallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');subplot(2,2,1),imshow(I);title('灰度图像');I=rgb2gray(I);subplot(2,2,1);imshow(I);subplot(2,2,2);imhist(I);I1=histeq(I);subplot(2,2,3);imshow(I1);subplot(2,2,4);imhist(I1);9线性平滑滤波原始图像加入躁声图像3*3摸板5*5摸板7*7摸板9*9摸板clearcloseallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');subplot(2,3,1),imshow(I);title('原始图像')I=rgb2gray(I);I1=imnoise(I,'salt&pepper',0.02);subplot(2,3,2),imshow(I1);title('加入躁声图像')k1=filter2(fspecial('average',3),I1)/255;k2=filter2(fspecial('average',5),I1)/255;k3=filter2(fspecial('average',7),I1)/255;k4=filter2(fspecial('average',9),I1)/255;subplot(2,3,3),imshow(k1);title('3*3摸板')subplot(2,3,4),imshow(k2);title('5*5摸板')subplot(2,3,5),imshow(k3);title('7*7摸板')subplot(2,3,6),imshow(k4);title('9*9摸板')10中值滤波原图像添加椒盐噪声图像3*3模板中值滤波5*5模板中值滤波7*7模板中值滤波9*9模板中值滤波clearcloseallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');I=rgb2gray(I);J=imnoise(I,'salt&pepper',0.02);subplot(2,3,1),imshow(I);title('原图像');subplot(2,3,2),imshow(J);title('添加椒盐噪声图像');k1=medfilt2(J);k2=medfilt2(J,[5,5]);k3=medfilt2(J,[7,7]);k4=medfilt2(J,[9,9]);subplot(2,3,3),imshow(k1);title('3*3模板中值滤波');subplot(2,3,4),imshow(k2);title('5*5模板中值滤波');subplot(2,3,5),imshow(k3);title('7*7模板中值滤波');subplot(2,3,6),imshow(k4);title('9*9模板中值滤波');11用sobel算子和拉普拉丝对图象锐化原始图像500100015002004006008001000二值图像500100015002004006008001000sobel算子锐化图像5010015020025050100150200拉普拉斯算子锐化图像500100015002004006008001000clearcloseallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');subplot(2,2,1),imshow(I);title('原始图像');gridon;axison;I1=im2bw(I);subplot(2,2,2),imshow(I1);title('二值图像');gridon;axison;H=fspecial('sobel');J=filter2(H,I1);subplot(2,2,3),imshow(J);title('sobel算子锐化图像');axis([50,250,50,200]);gridon;axison;h=[010,1-41,010];I1=double(I1);%缺少转化J1=conv2(I1,h,'same');subplot(2,2,4),imshow(J1);title('拉普拉斯算子锐化图像');gridon;axison;12真彩色分解原始真彩色图像真彩色图像的红色分量真彩色图像的绿色分量真彩色图像的蓝色分量RGB=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');subplot(221),imshow(RGB)title('原始真彩色图像')subplot(222),imshow(RGB(:,:,1))title('真彩色图像的红色分量')subplot(223),imshow(RGB(:,:,2))title('真彩色图像的绿色分量')subplot(224),imshow(RGB(:,:,3))title('真彩色图像的蓝色分量')13伪彩色增强举例clearcloseallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');subplot(121),imshow(I);X=grayslice(I,16);subplot(122),imshow(X,hot(16));14、梯度算子检测边缘原始图像500100015002004006008001000二值图像500100015002004006008001000roberts算子分割结果500100015002004006008001000sobel算子分割结果500100015002004006008001000Prewitt算子分割结果500100015002004006008001000clearcloseallI=imread('C:\DocumentsandSettings\Administrator\桌面\图片\2.jpg');subplot(2,3,1);imshow(I);title('原始图像');gridon;axison;I1=im2bw(I);subplot(2,3,2);imshow(I1);title('二值图像');gridon;axison;I1=double(I1);I2=edge(I1,'roberts');subplot(2,3,3);imshow(I2);title('roberts算子分割结果');gridon;axison;I3=edge(I1,'sobel');subplot(2,3,4);imshow(I3);title('sobel算子分割结果');gridon;axison;I4=edge(I1,'Prewitt');subplot(2,3,5);imshow(I4);title('Prewitt算子分割结果');gridon;axison;15、log算子检测边缘原始图像灰度图像log算子分割结果clea
本文标题:数字图像处理指令及效果
链接地址:https://www.777doc.com/doc-2387957 .html