⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageprocess.m

📁 图像处理GUI代码
💻 M
📖 第 1 页 / 共 2 页
字号:
%        str2double(get(hObject,'String')) returns contents of lowpass_fh as a double% set/get 函数是用来设置/获取某个控件属性% 使用get命令获取第一个加数,并将它转换成数值input = str2num(get(hObject,'String')); % string属性是字符串,所以必须转换成数值% 检验输入是否为空,是则将它置为0if (isempty(input))     set(hObject,'String','50');else    d0 = str2num(get(handles.bocktor_fh,'String'));    a1= handles.img;    a2=double(a1);%巴特沃斯滤波开始    a3=fft2(a2);    a3=fftshift(a3);    [N1,N2]=size(a3);    n=2;    n1=fix(N1/2);    n2=fix(N2/2);for i=1:N1    for j=1:N2        d=sqrt((i-n1)^2+(j-n2)^2);        h=1/((1+d/d0)^(2*n));        result1(i,j)=h*a3(i,j);    endendresult=ifftshift(result1);g=ifft2(result);g1=uint8(real(g));figure;subplot(1,2,1);imshow(a1);title('原始图像');subplot(1,2,2);imshow(g1);title('巴特沃斯低通滤波后的图像');endguidata(hObject, handles);% --- Executes during object creation, after setting all properties.function bocktor_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 noisedense_Callback(hObject, eventdata, handles)% hObject    handle to noisedense (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 noisedense as text%        str2double(get(hObject,'String')) returns contents of noisedense as a doubleinput = str2num(get(hObject,'String')); % string属性是字符串,所以必须转换成数值% 检验输入是否为空,是则将它置为0a1=handles.img;if (isempty(input))     set(hObject,'String','0');elsehandles.noise.img=imnoise(a1,'salt',input);n_img=handles.noise.img; figure;subplot(1,2,1);imshow(a1);title('原始图像');subplot(1,2,2);imshow(n_img);title('加盐噪声后的图像');endguidata(hObject, handles);% --- Executes during object creation, after setting all properties.function noisedense_CreateFcn(hObject, eventdata, handles)% hObject    handle to noisedense (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% --- 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)% --- Executes on selection change in weaner_size.function weaner_size_Callback(hObject, eventdata, handles)% hObject    handle to weaner_size (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 weaner_size contents as cell array%        contents{get(hObject,'Value')} returns selected item from weaner_size% --- Executes during object creation, after setting all properties.function weaner_size_CreateFcn(hObject, eventdata, handles)% hObject    handle to weaner_size (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: listbox 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 selection change in popupmenu3.function popupmenu3_Callback(hObject, eventdata, handles)% hObject    handle to popupmenu3 (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 popupmenu3 contents as cell array%        contents{get(hObject,'Value')} returns selected item from popupmenu3% --- Executes during object creation, after setting all properties.function popupmenu3_CreateFcn(hObject, eventdata, handles)% hObject    handle to popupmenu3 (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 selection change in popupmenu4.function popupmenu4_Callback(hObject, eventdata, handles)% hObject    handle to popupmenu4 (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 popupmenu4 contents as cell array%        contents{get(hObject,'Value')} returns selected item from popupmenu4% --- Executes during object creation, after setting all properties.function popupmenu4_CreateFcn(hObject, eventdata, handles)% hObject    handle to popupmenu4 (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 selection change in weanermenu.function weanermenu_Callback(hObject, eventdata, handles)% hObject    handle to weanermenu (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 weanermenu contents as cell array%        contents{get(hObject,'Value')} returns selected item from weanermenuvalue=get(hObject,'value');n_img=handles.noise.img;switch value     case 1      handles.weaner.img1=wiener2(n_img,[2 2]);      figure;      subplot(1,2,1);      imshow(n_img);      title('加椒盐噪声后的图像');      subplot(1,2,2);      imshow(handles.weaner.img1);      title('维纳滤波恢复后的图像');     case 2      handles.weaner.img1=wiener2(n_img,[4 4]);        figure;      subplot(1,2,1);      imshow(n_img);      title('加椒盐噪声后的图像');      subplot(1,2,2);      imshow(handles.weaner.img1);      title('维纳滤波恢复后的图像');     case 3      handles.weaner.img1=wiener2(n_img,[6 6]); %维纳滤波      figure;      subplot(1,2,1);      imshow(n_img);      title('加椒盐噪声后的图像');      subplot(1,2,2);      imshow(handles.weaner.img1);      title('维纳滤波恢复后的图像');     case 4      handles.weaner.img1=wiener2(n_img,[8 8]);      figure;      subplot(1,2,1);      imshow(n_img);      title('加椒盐噪声后的图像');      subplot(1,2,2);      imshow(handles.weaner.img1);      title('维纳滤波恢复后的图像');     case 5      handles.weaner.img1=wiener2(n_img,[10 10]);       figure;      subplot(1,2,1);      imshow(n_img);      title('加椒盐噪声后的图像');      subplot(1,2,2);      imshow(handles.weaner.img1);      title('维纳滤波恢复后的图像');     case 6      handles.weaner.img1=wiener2(n_img,[12 12]);       figure;      subplot(1,2,1);      imshow(n_img);      title('加椒盐噪声后的图像');      subplot(1,2,2);      imshow(handles.weaner.img1);      title('维纳滤波恢复后的图像');     guidata(hObject, handles);     end% --- Executes during object creation, after setting all properties.function weanermenu_CreateFcn(hObject, eventdata, handles)% hObject    handle to weanermenu (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 midfilter_run.function midfilter_run_Callback(hObject, eventdata, handles)% hObject    handle to midfilter_run (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)a1= handles.img;n_img=handles.noise.img;J0=handles.midfilter.img;handles.weaner.img2=wiener2(J0,[10 10]);J1=handles.weaner.img2;figure;subplot(2,2,1);imshow(a1);title('原始图像');subplot(2,2,2);imshow(n_img);title('加椒盐噪声后的图像');subplot(2,2,3);imshow(J0);title('中值滤波后的图像');subplot(2,2,4);imshow(J1);title('维纳滤波后的图像');guidata(hObject, handles);%中值滤波部分%%下拉菜单进行滤波窗口大小的选择,滤波后把图像存放在handles.midfilter.img中,供后续显示使用%% --- Executes on selection change in midfilter_menu.function midfilter_menu_Callback(hObject, eventdata, handles)% hObject    handle to midfilter_menu (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 midfilter_menu contents as cell array%        contents{get(hObject,'Value')} returns selected item from midfilter_menuvalue=get(hObject,'value');n_img=handles.noise.img;switch value     case 1      handles.midfilter.img=medfilt2(n_img,[3 3]);     case 2      handles.midfilter.img=medfilt2(n_img,[5 5]);       case 3      handles.midfilter.img=medfilt2(n_img,[9 9]);             case 4      handles.midfilter.img=medfilt2(n_img,[11 11]);             guidata(hObject, handles);     end% --- Executes during object creation, after setting all properties.function midfilter_menu_CreateFcn(hObject, eventdata, handles)% hObject    handle to midfilter_menu (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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -