请帮我更改一下代码让图片显示与原图片大小一致,function Exponential_high_filter_Callback(hObject, eventdata, handles)%指数高通滤波 % hObject handle to Exponential_high_filter (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axis off; %%关闭坐标轴显示 global im; %%声明全局变量 global str; im = imread(str); Image=imnoise(im,'gaussian'); FImage=fftshift(fft2(double(Image))); [N,M]=size(FImage); g=zeros(N,M); r1=floor(M/2); r2=floor(N/2); d0=[20 50]; %截断频率 为 D0=50 n=2; for i=1:2 for x=1:M for y=1:N d=sqrt((x-r1)^2+(y-r2)^2); h=exp(-0.5*(d0(i)/d)^n); g(y,x)=h*FImage(y,x); end end g=ifftshift(g); g=real(ifft2(g)); end axes(handles.axes2); imshow(uint8(g));
时间: 2024-03-15 12:41:46 浏览: 94
在imshow函数中添加参数"InitialMagnification", "fit",即可让图片显示与原图片大小一致。更改后的代码如下:
function Exponential_high_filter_Callback(hObject, eventdata, handles)
%指数高通滤波
% hObject handle to Exponential_high_filter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axis off; %%关闭坐标轴显示
global im; %%声明全局变量
global str;
im = imread(str);
Image=imnoise(im,'gaussian');
FImage=fftshift(fft2(double(Image)));
[N,M]=size(FImage);
g=zeros(N,M);
r1=floor(M/2);
r2=floor(N/2);
d0=[20 50]; %截断频率 为 D0=50 n=2;
for i=1:2
for x=1:M
for y=1:N
d=sqrt((x-r1)^2+(y-r2)^2);
h=exp(-0.5*(d0(i)/d)^n);
g(y,x)=h*FImage(y,x);
end
end
g=ifftshift(g);
g=real(ifft2(g));
end
axes(handles.axes2);
imshow(uint8(g), 'InitialMagnification', 'fit');
阅读全文