高通滤波器滤波后
实现程序如下:
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles) % hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
axes(handles.axes2); y1=handles.img;
f=double(y1); % 数据类型转换,matlab不支持图像的无符号整型的计算 g=fft2(f); % 傅里叶变换 g=fftshift(g); % 转换数据矩阵 [M,N]=size(g);
nn=2; %二阶巴特沃斯低通滤波器 d0=50; %截止频率50 m=fix(M/2); n=fix(N/2); for i=1:M for j=1:N
d=sqrt((i-m)^2+(j-n)^2);
h=1/(1+0.414*(d/d0)^(2*nn)); % 计算低通滤波器传递函数 result(i,j)=h*g(i,j); end
25 / 52
end
result=ifftshift(result); y2=ifft2(result); y3=uint8(real(y2));
imshow(y3); % 显示处理后的图像
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles) % hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
axes(handles.axes2); x=(handles.img);
f=double(x); % 数据类型转换 k=fft2(f); % 傅里叶变换 g=fftshift(k); % 转换数据矩阵 [M,N]=size(g); nn=2;
d0=25; %截止频率25 m=fix(M/2); n=fix(N/2); for i=1:M
for j=1:N
d=sqrt((i-m)^2+(j-n)^2); % 计算高通滤波器传递函数 if d<=d0
26 / 52
h=0; else h=1; end
result(i,j)=h*g(i,j); end end
result=ifftshift(result); y2=ifft2(result); y3=uint8(real(y2));
imshow(y3); % 显示滤波处理后的图像 4.9还原
通过一个全局变量保存原始图像路径,在需要还原至原始图像时,重新读取该全局变量即可。 实现程序段如下:
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles) % hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global S %还原 axes(handles.axes2); y=imread(S); f=imshow(y); handles.img=y;
guidata(hObject,handles); 4.10 撤销。
撤销上一步的操作。通过另设一个全局变量T保存是上一次操作后的图像。
27 / 52
实现程序段如下:
--- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles) % hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes2); %撤销 global T imshow(T); handles.img=T;
guidata(hObject,handles);
该程序段只是简单的显示图像的功能,其中全局变量T中储存的是上一步操作处理后的图像信息。在以上的各段功能程序段中可见均有 “T=getimage;”,此句把当前操作前的图像,即上一次操作后的图像信息赋予全局变量T。
4.11 图像变形。
(1)图像翻转。实现图像的镜像翻转。 左右翻转:
上下翻转
28 / 52