matlab图像处理的几个实例

matlab图像处理的几个实例


2024年1月8日发(作者:)

Matlab 图象处理(tú xiànɡ chǔ lǐ)的几个实例(初学者用)

1.图象的基本(jīběn)信息及其加减乘除

clear,clc;

P=imread('');

whos P

Q=imread('');

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),imshow(P),title('郁金香原图(yuán tú)');

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(428),imshow(sf),title( 'P/Q');

2.图象(tú xiànɡ)缩放

clear,clc;

I=imread('');

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]);

figure

subplot(321),imshow(I),title('原图(yuán tú)');

subplot(322),imshow(A),title('最邻近插值');

subplot(323),imshow(B),title('双线性插值');

subplot(324),imshow(C),title('二次立方插值');

subplot(325),imshow(D),title('水平缩放与垂直缩放比例为subplot(326),imshow(F),title('水平缩放与垂直缩放比例为);

);

2:1' 1:4'

灰度变换(biànhuàn)、直方图变换

clear,clc;

fg=imread('');

zl=imread('');

hfg=rgb2gray(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);

figure

subplot(421),imshow(fg1),title('复古(fùgǔ)灰度图');

subplot(422),imhist(fg1),title('复古(fùgǔ)灰度图的直方图');

subplot(423),imshow(out1),title('对复古(fùgǔ)灰度图象进行幂次变换');

subplot(424),imhist(out1),title 幂次变换(biànhuàn)图象的直方图');

subplot(425),imshow(img),title('朱莉');

subplot(426),imhist(img),title('朱莉图象对应的直方图');

subplot(427),imshow(J),title('直方图变换后的复古图');

subplot(428),imhist(J),title('直方图变换后的复古图对应的直方图');

傅里叶变换(biànhuàn)、频域滤波

1.傅里叶变换(biànhuàn)

clear,clc;

rgb=imread('');

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=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)=iflyfG;

out(:,:,3)=iflyfB;

figure

subplot(221),imshow(rgb),title( '原图(yuán tú)');

subplot(222),imshow(Frgb),title('图象(tú xiànɡ)频谱');

subplot(223),imshow(tzF),title('调整(tiáozhěng)中心后的图象频谱');

subplot(224),imshow(out),title('逆变换得到的原图');

2.频域滤波(lǜbō)

clear,clc;

I=rgb2gray(imread(''));

J=imnoise(I,'gaussian',0.1);

Jzz1=medfilt2(J,[3 3]);

Jzz2=medfilt2(J,[10 10]);

XJ=imnoise(I,'salt & pepper');

f=im2double(XJ);

g=fft2(f);

g=fftshift(g);

[M,N]=size(g);

nn=2;

d0=50;

m=fix(M/2);n=fix(M/2);

for i=1:M

for j=1:N

d=sqrt((i-m)^2+(j-n)^2);

h1=1/(1+0.414*(d/d0)^(2*nn));

result1(i,j)=h1*g(i,j);

end

end

result1=ifftshift(result1);

J2=ifft2(result1);

J3=im2uint8(real(J2));

figure

subplot(231),imshow(I),title('原图(yuán tú)的灰度图象');

subplot(232),imshow(J),title('加高斯(ɡāo sī)噪声');

subplot(233),imshow(Jzz1),title('模板 3*3 中值(zhōnɡ zhí)滤波后的图

像');

subplot(234),imshow(Jzz2),title('模板(múbǎn)10*10 中值滤波后的图象

');

subplot(235),imshow(J3),title('低通滤波图');

彩色图象处理(chǔlǐ)

clear,clc;

rgb=imread('');

fR=rgb(:,:,1);

fG=rgb(:,:,2);

fB=rgb(:,:,3);

R=rgb;

R(:,:,[2 3])=0;

G=rgb;

G(:,:,[1 3])=0;

B=rgb;

B(:,:,[1 2])=0;

yiq=rgb2ntsc(rgb);

fY=yiq(:,:,1);

fI=yiq(:,:,2);

fQ=yiq(:,:,3);

fR=histeq(fR,256);

fG=histeq(fG,256);

fB=histeq(fB,256);

RGB=cat(3,fR,fG,fB);

figure

subplot(341),imshow(rgb),title( '原图(yuán tú)');

subplot(342),imshow(R),title('图象的红色(hóngsè)分量');

subplot(343),imshow(G),title('图象(tú xiànɡ)的绿色分量');

subplot(344),imshow(B),title('图象(tú xiànɡ)的蓝色分量');

subplot(345),imshow(yiq),title('NTSC 彩色空间');

subplot(346),imshow(fY),title('亮度');

subplot(347),imshow(fI),title('色调');

subplot(348),imshow(fQ),title('饱和度');

subplot(349),imshow(RGB),title('rgb 均衡化后的彩色图象');

内容总结

(1) Matlab 图象处理的几个实例(初学者用)

1.图象的基本信息及其加减乘除clear,clc

(2) Matlab 图象处理的几个实例(初学者用)

1.图象的基本信息及其加减乘除clear,clc

(3) P=imread('')

(4) I=imread('')

(5) fg=imread('')

(6) zl=imread('')

(7)傅里叶变换、频域滤波

傅里叶变换clear,clc


发布者:admin,转转请注明出处:http://www.yc00.com/web/1704702661a1363781.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信