matlab代码.docx
- 文档编号:26026736
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:12
- 大小:250.73KB
matlab代码.docx
《matlab代码.docx》由会员分享,可在线阅读,更多相关《matlab代码.docx(12页珍藏版)》请在冰豆网上搜索。
matlab代码
1-3
%fft2Dbitmap_image.m
%SimulationofFouriertransformationofbitmapimages
clear
I=imread('triangle.bmp','bmp');%Inputbitmapimage
I=I(:
:
1);
figure
(1)%displayinginput
colormap(gray(255));
image(I)
axisoff
FI=fft2(I);
FI=fftshift(FI);
max1=max(FI);
max2=max(max1);
scale=1.0/max2;
FI=FI.*scale;
figure
(2)%Grayscaleimageoftheabsolutevalueoftransform
colormap(gray(255));
image(10*(abs(256*FI)));
axisoff
1-4
%correlation.m
clear
I1=imread('smiley1.bmp','bmp');%Inputimage1(referenceimage)
I1=I1(:
:
1);
figure
(1)%displayinginputimage1
colormap(gray(255));
image(I1)
axisoff
FI1=fft2(I1);
max1=max(FI1);
max2=max(max1);
scale=1.0/max2;
FI1=FI1.*scale;
I2=imread('smiley1.bmp','bmp');%Inputimage2(imagetoberecognized)
I2=I2(:
:
1);
figure
(2)%displayinginputimage2
colormap(gray(255));
image(I2)
axisoff
FI2=fft2(I2);
max1=max(FI2);
max2=max(max1);
scale=1.0/max2;
FI2=FI2.*scale;
FPR=FI1.*conj(FI2);%calculatingcorrelation
PR=ifft2(FPR);
PR=fftshift(PR);
max1=max(PR);
max2=max(max1);
scale=1.0/max2;
PR=PR.*scale;
figure(3)%displayofcorrelationinspatialdomain
colormap(gray(255));
image(abs(256*PR));
axisoff
fftshift只是将fft2的结果移了下位,fft2的左下部分和右上部分对调,左上部分和右下部分对调,结果fft2的零频移到fft2得到矩阵的中心,这时可以看到中心一个亮点,要不然零频就分布在矩阵的四个角,中间一片黑
2-1
%Fresnel_diffraction.m
%SimulationofFresneldiffractionofasquareaperture
%Adaptedfrom"ContemporaryopticalimageprocessingwithMATLAB®,"
%byT.-C.PoonandP.P.Banerjee,Elsevier2001,pp.64-65.
clear
L=1;%L:
lengthofdisplayarea
N=256;%N:
numberofsamplingpoints
dx=L/(N-1);%dx:
stepsize
%Createsquareimage,MbyMsquare,rect(x/a),M=oddnumber
M=111;
a=M/256
R=zeros(256);%assignamatrix(256x256)ofzeros
r=ones(M);%assignamatrix(MxM)ofones
n=(M-1)/2;
R(128-n:
128+n,128-n:
128+n)=r;
%Endofcreatinginputimage
%AxisScaling
fork=1:
256
X(k)=1/255*(k-1)-L/2;
Y(k)=1/255*(k-1)-L/2;
%Kx=(2*pi*k)/((N-1)*dx)
%inourcase,N=256,dx=1/255
Kx(k)=(2*pi*(k-1))/((N-1)*dx)-((2*pi*(256-1))/((N-1)*dx))/2;
Ky(k)=(2*pi*(k-1))/((N-1)*dx)-((2*pi*(256-1))/((N-1)*dx))/2;
end
%FouriertransformationofR
FR=(1/256)^2*fft2(R);
FR=fftshift(FR);
%Freespaceimpulseresponsefunction
%Theconstantfactorexp(-jk0*z)isnotcalculated
%sigma=ko/(2*z)=pi/(wavelength*z)
%z=5cm,redlight=0.6328*10^-4(cm)
sigma=pi/((0.6328*10^-4)*5);
forr=1:
256,
forc=1:
256,
%computefree-spaceimpulseresponsewithGaussianapodizationagainstaliasing
h(r,c)=j*(sigma/pi)*exp(-4*200*(X(r).^2+Y(c).^2))*exp(-j*sigma*(X(r).^2+Y(c).^2));
end
end
H=(1/256)^2*fft2(h);
H=fftshift(H);
HR=FR.*H;
H=(1/256)^2*fft2(h);
H=fftshift(H);
HR=FR.*H;
hr=ifft2(HR);
hr=(256^2)*hr;
hr=fftshift(hr);
%Imageoftherectangleobject
figure
(1)
image(X,Y,255*R);
colormap(gray(256));
axissquare
xlabel('cm')
ylabel('cm')
%plotofcrosssectionofsquare
figure
(2)
plot(X+dx/2,R(:
127))
grid
axis([-0.50.5-0.11.2])
xlabel('cm')
figure(3)
plot(X+dx/2,abs(hr(:
127)))
grid
axis([-0.50.50max(max(abs(hr)))*1.1])
xlabel('cm')
a=
0.4336
2-2
%Fresnel_zone_plate.m
%Adaptedfrom"ContemporaryopticalimageprocessingwithMATLAB®,"
%byT.-C.PoonandP.P.Banerjee,Elsevier2001,pp.177-178.
%
%displayfunctionis1+sin(sigma*((x-x0)^2+(y-y0)^2)).Allscalesarearbitrary.
%sigma=pi/(wavelength*z)
clear;
z0=input('z0,distancefromthepointobjecttofilm,enterz0(from2to10)=');
x0=input('InputtingthelocationofthecenteroftheFZPx0=y0,enterx0(from-8to8)=');
ROWS=256;
COLS=256;
colormap(gray(255))
sigma=1/z0;
y0=-x0;
y=-12.8;
forr=1:
COLS,
x=-12.8;
forc=1:
ROWS,%computeFresnelzoneplate
fFZP(r,c)=exp(j*sigma*(x-x0)*(x-x0)+j*sigma*(y-y0)*(y-y0));
x=x+.1;
end
y=y+.1;
end
%normalization
max1=max(fFZP);
max2=max(max1);
scale=1.0/max2;
fFZP=fFZP.*scale;
R=127*(1+imag(fFZP));
figure
(1)
image(R);
axissquareon
axisoff
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)