《图像处理matlab程序实例》由会员分享,可在线阅读,更多相关《图像处理matlab程序实例(13页珍藏版)》请在金锄头文库上搜索。
1、程序实例1 旋转:x=imread(d:MATLAB7workflower.jpg);y=imrotate(x,200,bilinear,crop);subplot(1,2,1);imshow(x);subplot(1,2,2);imshow(y)2.图像的 rgb clearx,map=imread(D:Program FilesMATLABR2012abinshaohaiheshh1.jpg);y=x(90:95,90:95);imshow(y)R=x(90:95,90:95,1);G=x(90:95,90:95,2);B=x(90:95,90:95,3);R,G,B3.加法运算clear
2、I=imread(D:Program FilesMATLABR2012abinshaohaiheshh3.jpg);J=imnoise(I,gaussian,0,0.02);% 向图片加入高斯噪声subplot(1,2,1),imshow(I); %显示图片 subplot(1,2,2),imshow(J);K=zeros(242,308); %产生全零的矩阵,大小与图片的大小一样for i=1:100 %循环100加入噪声J=imnoise(I,gaussian,0,0.02);J1=im2double(J);K=K+J1;endK=K/100;figure,imshow(K);save4.
3、减法clearI=imread(D:Program FilesMATLABR2012abinshaohaiheshao.jpg);J=imread(D:Program FilesMATLABR2012abinshaohaiheshao1.jpg);K=imsubtract(I,J); %实现两幅图相减K1=255-K; %将图片求反显示 figure;imshow(I);title(有噪声的图); figure;imshow(J);title(原图); figure;imshow(K1);title(提取的噪声); save5.图像的乘法 H=imread(D:Program FilesMAT
4、LABR2012abinshaohaiheshao.jpg);I=immultiply(H,1.2); 将此图片乘以1.2 J=immultiply(H,2);subplot(1,3,1),imshow(H);title(原图); subplot(1,3,2),imshow(I);title(放大1.2); subplot(1,3,3),imshow(J);title(放大2倍);6 除法运算moon=imread(moon.tif);I=double(moon);J=I*0.43+90;K=I*0.1+90;L=I*0.01+90;moon2=uint8(J);moon3=uint8(K);
5、moon4=uint8(L);J=imdivide(moon,moon2);K=imdivide(moon,moon3);L=imdivide(moon,moon4);subplot(2,2,1),imshow(moon);subplot(2,2,2),imshow(J,);subplot(2,2,3),imshow(K,);subplot(2,2,4),imshow(L,);7.图像的缩放 clearI = imread(D:Program FilesMATLABR2012abinshaohaiheshao1.jpg);figure,imshow(I);scale = 0.5;J = imr
6、esize(I,scale);figure,imshow(J);8.图像的旋转 (1) I = imread(D:Program FilesMATLABR2012abinshaohaiheshao1.jpg);figure,imshow(I);theta = 30;K = imrotate(I,theta); % Try varying the angle, theta.figure, imshow(K) (2) clearI=imread(D:Program FilesMATLABR2012abinshaohaiheshao1.jpg);J=imrotate(I,60,bilinear);K
7、=imrotate(I,60,bilinear,crop);subplot(1,3,1),imshow(I);subplot(1,3,2),imshow(J);subplot(1,3,3),imshow(K);1. 傅里叶变换clearI=zeros(256,256);I(28:228,108:148)=1;imshow(I)求原始图像的傅里叶频谱 J=fft2(I);F=abs(J);J1=fftshift(F);figureimshow(J1,5,50clearI=zeros(256,256);I(28:228,108:148)=1;%对原始图像进行旋转 J=imrotate(I,315,
8、bilinear,crop);figureimshow(J)求原始图像的傅里叶频谱 J1=fft2(J);F=abs(J1);J2=fftshift(F);figureimshow(J2,5,50)1. 图象的图象的 FFT 变换变换 clc; I=imread(005.bmp); subplot(1,2,1) imshow(I); title(原图); subplot(1,2,2) imhist(I); title(直方图); colorbar; J=fft2(I); figure; subplot(1,2,1) imshow(J); title(FFT 变换结果); subplot(1,2
9、,2) K=fftshift(J); imshow(K); title(零点平移); figure; imshow(log(abs(K),),colormap(jet(64),colorbar; title(系数分布图);2. 图象的图象的 DCT 变换变换 RGB=imread(005.bmp); figure; subplot(1,2,1) imshow(RGB);title(彩色原图); a=rgb2gray(RGB); subplot(1,2,2) imshow(a); title(灰度图); figure; b=dct2(a); imshow(log(abs(b),),colormap(jet(64),colorbar; title(DCT 变换结果); figure; b(abs(b)T);Tnew=(mean(I(r1)+mean(I(r2)/2;done=abs(Tnew-T)1;T=Tnew;i=i+1;endI(r1)=0;I(r2)=1;figure;imshow(I)