资源描述:
《matlab图像处理的几个实例》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Matlab图像处理的几个实例(初学者用)1.图像的基本信息及其加减乘除clear,clc;P=imread('yjx.jpg');whosPQ=imread('dt.jpg');P=im2double(P);Q=im2double(Q);gg1=im2bw(P,0.3);gg2=im2bw(P,0.5);gg3=im2bw(P,0.8);K=imadd(gg1,gg2);L=imsubtract(gg2,gg3);cf=immultiply(P,Q);sf=imdivide(Q,P);subplot(421),im
2、show(P),title('郁金香原图');subplot(422),imshow(gg1),title('0.3');subplot(423),imshow(gg2),title('0.5');subplot(424),imshow(gg3),title('0.8');subplot(425),imshow(K),title('0.3+0.5');subplot(426),imshow(L),title('0.5-0.3');subplot(427),imshow(cf),title('P*Q');subplot
3、(428),imshow(sf),title('P/Q');2.图像缩放clear,clc;I=imread('dt.jpg');A=imresize(I,0.1,'nearest');B=imresize(I,0.4,'bilinear');C=imresize(I,0.7,'bicubic');D=imresize(I,[100,200]);F=imresize(I,[400,100]);figuresubplot(321),imshow(I),title('原图');subplot(322),imshow(A)
4、,title('最邻近插值');subplot(323),imshow(B),title('双线性插值');subplot(324),imshow(C),title('二次立方插值');subplot(325),imshow(D),title('水平缩放与垂直缩放比例为2:1');subplot(326),imshow(F),title('水平缩放与垂直缩放比例为1:4');灰度变换、直方图变换clear,clc;fg=imread('fg.jpg');zl=imread('zl.jpg');hfg=rgb2gray
5、(fg);fg1=double(hfg);out1=255*(fg1/255).^0.7;out1(find(out1>255))=255;fg1=uint8(fg1);out1=uint8(out1);img=rgb2gray(zl);[harm,x]=imhist(img);J=histeq(hfg,harm);figuresubplot(421),imshow(fg1),title('复古灰度图');subplot(422),imhist(fg1),title('复古灰度图的直方图');subplot(423)
6、,imshow(out1),title('对复古灰度图像进行幂次变换');subplot(424),imhist(out1),title('幂次变换图像的直方图');subplot(425),imshow(img),title('朱莉');subplot(426),imhist(img),title('朱莉图像对应的直方图');subplot(427),imshow(J),title('直方图变换后的复古图');subplot(428),imhist(J),title('直方图变换后的复古图对应的直方图');傅里叶变
7、换、频域滤波1.傅里叶变换clear,clc;rgb=imread('zl.jpg');rgb=imresize(rgb,0.7,'bilinear');rgb=im2double(rgb);fR=rgb(:,:,1);fG=rgb(:,:,2);fB=rgb(:,:,3);flyfR=fft2(fR);flyfG=fft2(fG);flyfB=fft2(fB);Frgb(:,:,1)=flyfR;Frgb(:,:,2)=flyfG;Frgb(:,:,3)=flyfB;tzR=fftshift(flyfR);tzG=
8、fftshift(flyfG);tzB=fftshift(flyfB);tzF(:,:,1)=tzR;tzF(:,:,2)=tzG;tzF(:,:,3)=tzB;iflyfR=ifft2(flyfR);iflyfG=ifft2(flyfG);iflyfB=ifft2(flyfB);out(:,:,1)=iflyfR;out(:,:,2)=ifl