📄 guicompare.m
字号:
set(hObject,'BackgroundColor',[.9 .9 .9]);
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on slider movement.
function sldnoisedensity_Callback(hObject, eventdata, handles)
% hObject handle to sldnoisedensity (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
value = sprintf('%.2f', get(handles.sldnoisedensity, 'Value'));
set(handles.lblnoisedensityval, 'String', value);
% --- Executes on button press in pbdegradeimg.function pbdegradeimg_Callback(hObject, eventdata, handles)% hObject handle to pbdegradeimg (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
global comein;
%Enter only if image is opened first
if evalin('base', 'cmpdegimstatus') >= 1 & comein >= 1
%Reading original image from base workspace
originalimg = evalin('base', 'originalimg');
LEN = str2num(get(handles.txtlength, 'String'));
THETA = str2num(get(handles.txttheta, 'String'));
%If noise is checked
if get(handles.chknoise, 'Value')
switch get(handles.popnoisetype, 'Value')
case 1 %salt & pepper
d = str2num(get(handles.lblnoisedensityval, 'String'));
degradedimg = degrade(originalimg, LEN, THETA, 'salt & pepper', d);
case 2 %gaussian
m = str2num(get(handles.lblmeanval, 'String'));
v = str2num(get(handles.lblvarianceval, 'String'));
degradedimg = degrade(originalimg, LEN, THETA, 'gaussian', m, v);
case 3 %poisson
degradedimg = degrade(originalimg, LEN, THETA, 'poisson');
case 4 %speckle
v = str2num(get(handles.lblvarianceval, 'String'));
degradedimg = degrade(originalimg, LEN, THETA, 'speckle', v);
end
else %noise is not checked
degradedimg = degrade(originalimg, LEN, THETA);
end
%Make the axisdegradedimg the current axes
axes(handles.axisdegradedimg);
imshow(real(degradedimg));
%Estimating SNR
R = str2num(sprintf('%.4f', 1/size(degradedimg, 2)));
set(handles.txtsnr, 'String', R);
set(handles.sldsnr, 'Value', R);
%Storing the degraded image in the base workspace
assignin('base','degradedimg',degradedimg);
%Setting start to 2 signifying image can be saved now
assignin('base', 'cmpdegimstatus', 2);
assignin('base', 'cmpresimstatus', 1);
%Hiding the frame
set(handles.frmdegradedimg, 'Visible', 'off');
else
uiwait(errordlg('Please open a file first.', 'Error', 'modal'));
end
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% --- Executes during object creation, after setting all properties.
function slditerations_CreateFcn(hObject, eventdata, handles)
% hObject handle to slditerations (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, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor',[.9 .9 .9]);
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on slider movement.
function slditerations_Callback(hObject, eventdata, handles)
% hObject handle to slditerations (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
str = sprintf('%.0f', get(handles.slditerations, 'Value'));
set(handles.txtiterations, 'String', str);
% --- Executes during object creation, after setting all properties.
function txtiterations_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtiterations (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function txtiterations_Callback(hObject, eventdata, handles)
% hObject handle to txtiterations (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 txtiterations as text
% str2double(get(hObject,'String')) returns contents of txtiterations as a double
str = str2num(get(handles.txtiterations,'String'));
if str<1 || str>1000
uiwait(errordlg('Please enter no. of iterations in the range 1 to 1000', 'Invalid Iterations', 'modal'));
%Resetting iterations
str = sprintf('%.0f', get(handles.slditerations, 'Value'));
set(handles.txtiterations, 'String', str);
else
set(handles.slditerations,'Value', str);
end
% --- Executes during object creation, after setting all properties.
function sldsnr_CreateFcn(hObject, eventdata, handles)
% hObject handle to sldsnr (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, change
% 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor',[.9 .9 .9]);
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on slider movement.
function sldsnr_Callback(hObject, eventdata, handles)
% hObject handle to sldsnr (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
str = sprintf('%.4f', get(handles.sldsnr, 'Value'));
set(handles.txtsnr, 'String', str);
% --- Executes during object creation, after setting all properties.
function txtsnr_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtsnr (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function txtsnr_Callback(hObject, eventdata, handles)
% hObject handle to txtsnr (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 txtsnr as text
% str2double(get(hObject,'String')) returns contents of txtsnr as a double
str = str2num(get(handles.txtsnr,'String'));
if str<0.0001 || str>1
uiwait(errordlg('Please enter Signal to Noise Ratio (SNR) in the range 0.0001 to 1', 'Invalid SNR', 'modal'));
%Resetting iterations
str = sprintf('%.4f', get(handles.sldsnr, 'Value'));
set(handles.txtsnr, 'String', str);
else
set(handles.sldsnr,'Value', str);
end
function [restoredimg] = restoreimage(hObject, eventdata, handles, filter)
%Reading the degraded image from the base workspace
degradedimg = evalin('base', 'degradedimg');
LEN = str2num(get(handles.txtlength, 'String'));
THETA = str2num(get(handles.txttheta, 'String'));
%Start the waitbar
handle = waitbar(0,'Please wait...');
switch filter
case 1 %Inverse filter
restoredimg = Inverse(degradedimg, LEN, THETA, handle);
axes(handles.axisinverse);
assignin('base','restoredinverse',restoredimg);
set(handles.frminverse, 'Visible', 'off');
case 2 %Wiener filter
SNR = get(handles.sldsnr, 'Value');
restoredimg = Wiener(degradedimg, LEN, THETA, SNR, handle);
axes(handles.axiswiener);
assignin('base','restoredwiener',restoredimg);
set(handles.frmwiener, 'Visible', 'off');
case 3 %Lucy-Richardson
iterations = floor(get(handles.slditerations, 'Value'));
restoredimg = Lucy(degradedimg, LEN, THETA, iterations, handle);
axes(handles.axislucy);
assignin('base','restoredlucy',restoredimg);
set(handles.frmlucy, 'Visible', 'off');
end
%Close the waitbar
close(handle);
%Display restored image
imshow(real(restoredimg));
function dispcomparison(hObject, eventdata, handles, restoredimg, filter)
originalimg = evalin('base', 'originalimg');
[absdiff, snr, psnr, imfid, mse] = compare(originalimg, restoredimg);
absdiff = sprintf('%.6f', real(absdiff));
snr = sprintf('%.6f', real(snr));
psnr = sprintf('%.6f', real(psnr));
imfid = sprintf('%.6f', real(imfid));
mse = sprintf('%.6f', real(mse));
switch filter
case 1 %Inverse Filter
set(handles.inverseaad, 'String', absdiff);
set(handles.inversesnr, 'String', snr);
set(handles.inversepsnr, 'String', psnr);
set(handles.inverseif, 'String', imfid);
set(handles.inversemse, 'String', mse);
case 2 %Wiener Filter
set(handles.wieneraad, 'String', absdiff);
set(handles.wienersnr, 'String', snr);
set(handles.wienerpsnr, 'String', psnr);
set(handles.wienerif, 'String', imfid);
set(handles.wienermse, 'String', mse);
case 3 %Lucy - Richardson Filter
set(handles.lucyaad, 'String', absdiff);
set(handles.lucysnr, 'String', snr);
set(handles.lucypsnr, 'String', psnr);
set(handles.lucyif, 'String', imfid);
set(handles.lucymse, 'String', mse);
end
% --- Executes on button press in pbinverse.function pbinverse_Callback(hObject, eventdata, handles)% hObject handle to pbinverse (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
global comein;
%Enter only if image is opened first
if evalin('base', 'cmpresimstatus') >= 1 & comein >= 1
restoredimg = restoreimage(hObject, eventdata, handles, 1);
dispcomparison(hObject, eventdata, handles, restoredimg, 1);
else
uiwait(errordlg('Please degrade a file first.', 'Error', 'modal'));
end
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% --- Executes on button press in pbwiener.function pbwiener_Callback(hObject, eventdata, handles)% hObject handle to pbwiener (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
global comein;
%Enter only if image is opened first
if evalin('base', 'cmpresimstatus') >= 1 & comein >= 1
restoredimg = restoreimage(hObject, eventdata, handles, 2);
dispcomparison(hObject, eventdata, handles, restoredimg, 2);
else
uiwait(errordlg('Please degrade a file first.', 'Error', 'modal'));
end
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% --- Executes on button press in pblucy.function pblucy_Callback(hObject, eventdata, handles)% hObject handle to pblucy (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
global comein;
%Enter only if image is opened first
if evalin('base', 'cmpresimstatus') >= 1 & comein >= 1
restoredimg = restoreimage(hObject, eventdata, handles, 3);
dispcomparison(hObject, eventdata, handles, restoredimg, 3);
else
uiwait(errordlg('Please degrade a file first.', 'Error', 'modal'));
end
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
% --- Executes on button press in pbhelp.
function pbhelp_Callback(hObject, eventdata, handles)
% hObject handle to pbhelp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.lblstatus, 'Foregroundcolor', 'Red');
set(handles.lblstatus, 'String', 'Status: Busy');
set(gcf,'pointer','watch');
web ([cd '\Help\Degrade.html'], '-browser');
set(gcf,'pointer','arrow');
set(handles.lblstatus, 'String', 'Status: Ready', 'Foregroundcolor', 'Black');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -