amira - I would create one function that all of your checkbox callbacks would call whenever the checkbox is checked or unchecked. This single function would then apply (or remove) the noise depending upon which checkbox is checked. For example, your first and second checkboxes would be replaced with just
function checkbox1_Callback(hObject, eventdata, handles)
applyNoise(handles);
function checkbox2_Callback(hObject, eventdata, handles)
applyNoise(handles);
The applyNoise function would then
function applyNoise(handles)
if isfield(handles,'imgData')
imgData = handles.imgData;
noiseStr = '';
if get(handles.checkbox1,'Value')
noiseStr = 'Salt & pepper';
imgData = imnoise(imgData,'salt & pepper',0.3);
end
if get(handles.checkbox2,'Value')
if ~isempty(noiseStr)
noiseStr = [noiseStr ', '];
end
noiseStr = [noiseStr 'Gaussian'];
imgData = imnoise(imgData,'gaussian',0.1,0.1);
end
axes(handles.axes2);
imshow(imgData);
title(['Noise type: ' noiseStr]);
end
The above function gets the initial image and first applies the Salt and Pepper noise followed by the Gaussian noise (if either has been selected) before being displayed in axes2. If neither has been selected, then there is no noise and so the original image is displayed in axes2.
You can do the same for the remaining three noise types.
Best Answer