📄 imageprocess.m
字号:
function varargout = imageprocess(varargin)% IMAGEPROCESS M-file for imageprocess.fig% IMAGEPROCESS, by itself, creates a new IMAGEPROCESS or raises the existing% singleton*.%% H = IMAGEPROCESS returns the handle to a new IMAGEPROCESS or the handle to% the existing singleton*.%% IMAGEPROCESS('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in IMAGEPROCESS.M with the given input arguments.%% IMAGEPROCESS('Property','Value',...) creates a new IMAGEPROCESS or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before imageprocess_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to imageprocess_OpeningFcn via varargin.%% *See GUI Options on GUIDE's Tools weanermenu. Choose "GUI allows only one% instance to weaner_run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help imageprocess% Last Modified by GUIDE v2.5 26-Apr-2012 22:38:05% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @imageprocess_OpeningFcn, ... 'gui_OutputFcn', @imageprocess_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before imageprocess is made visible.function imageprocess_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to imageprocess (see VARARGIN)% Choose default command line output for imageprocesshandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes imageprocess wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = imageprocess_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;% --- Executes on button press in base_transfer.function base_transfer_Callback(hObject, eventdata, handles)% hObject handle to base_transfer (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%I1=imread('me.jpg');%figure;%Hbutton=uicontrol('style','pushbutton');%imshow(I1);%y=imnoise(handles.img,'gaussian');%imshow(y);% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in file.function exit_Callback(hObject, eventdata, handles)% hObject handle to file (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)clc;close all;close(gcf); % --- Executes on selection change in spatial_operate.function spatial_operate_Callback(hObject, eventdata, handles)% hObject handle to spatial_operate (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = cellstr(get(hObject,'String')) returns spatial_operate contents as cell array% contents{get(hObject,'Value')} returns selected item from spatial_operate% --- Executes during object creation, after setting all properties.function spatial_operate_CreateFcn(hObject, eventdata, handles)% hObject handle to spatial_operate (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end% --- Executes on button press in togglebutton1.function togglebutton1_Callback(hObject, eventdata, handles)% hObject handle to togglebutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hint: get(hObject,'Value') returns toggle state of togglebutton1% --------------------------------------------------------------------function file_Callback(hObject, eventdata, handles)% hObject handle to file (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%文件打开%% --------------------------------------------------------------------function open_Callback(hObject, eventdata, handles)% hObject handle to file (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%I1=imread('me.jpg');%handles.img=I1;%figure;%imshow(I1); [name,path]=uigetfile({'*.jpg'},'载入图像'); if isequal(name,0)|isequal(path,0) errordlg('没有选中文件','出错'); return; else init_img=imread([path,name]); %axes(handles.axes2); end if(isrgb(init_img)) %msgbox('必需为灰度图像!'); x=rgb2gray(init_img); subplot(1,3,2); imshow(init_img); title('打开的图像为'); %axes(handles.axes1); %figure; subplot(1,3,3); imshow(x); title('相应的灰度图像为'); else x=init_img; subplot(1,2,2); imshow(init_img); title('打开的图像为'); end handles.img=x;%设置以下5个全局变量 handles.noise.img=x; handles.weaner.img1=x; handles.weaner.img2=x; handles.midfilter.img=x; guidata(hObject,handles);% --------------------------------------------------------------------function save_Callback(hObject, eventdata, handles)% hObject handle to save (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) %文件保存 [filename,pathname] = uiputfile('*.jpg','图片保存为'); if isequal([filename,pathname],[0,0]) errordlg('没有保存','出错'); return; else file=strcat(pathname,filename); %(handles.axes2); i=getimage(gca); imwrite(i,file);end% --------------------------------------------------------------------function edit_Callback(hObject, eventdata, handles)% hObject handle to edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on slider movement.function lightting_Callback(hObject, eventdata, handles)% hObject handle to lightting (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'Value') returns position of slider% get(hObject,'Min') and get(hObject,'Max') to determine range of slider% --- Executes during object creation, after setting all properties.function lightting_CreateFcn(hObject, eventdata, handles)% hObject handle to lightting (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background.if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);end%理想低通滤波器实验部分%%动态文本框接收截止频率的输入%function lowpass_fh_Callback(hObject, eventdata, handles)%% hObject handle to lowpass_fh (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of lowpass_fh as text% str2double(get(hObject,'String')) returns contents of lowpass_fh% as a doubled0=str2num(get(handles.lowpass_fh,'String'));%把文本框输入的字符串转为数a1= handles.img;a2=double(a1);a3=fft2(a2);%在频域进行滤波a3=fftshift(a3);[N1,N2]=size(a3);n1=fix(N1/2);n2=fix(N2/2);for i=1:N1 for j=1:N2 d=sqrt((i-n1)^2+(j-n2)^2); if(d>d0) result(i,j)=0;%构造理想低通滤波器,并滤波 else result(i,j)=a3(i,j); end endendresult=ifftshift(result);g=ifft2(result);%时间域显示滤波后的想像g1=uint8(real(g));figure;subplot(1,2,1);imshow(a1);title('原始图像');subplot(1,2,2);imshow(g1);title('理想低通滤波后的图像');% --- Executes during object creation, after setting all properties.function lowpass_fh_CreateFcn(hObject, eventdata, handles)% hObject handle to lowpass_fh (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end%巴特沃斯低通滤波部分%%接收动态文本框输入的截止频率,展示巴特沃斯低通滤波后的模糊效果%function bocktor_fh_Callback(hObject, eventdata, handles)% hObject handle to lowpass_fh (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of lowpass_fh as text
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -