Clear Filters
Clear Filters

How to combine multiple noise type using checkbox. for example double noise and triple noise and apply it to the image when click the checkbox

1 view (last 30 days)
I have 5 checkbox that represent 5 types of noise which is salt&pepper noise,localvar noise,gaussian noise, speckle noise and poisson noise. i want the user to be able to select multiple noise which is double noise or triple noise by clicking the checkbox and the noises will apply to the image.and after user click the checkboxes at the top of the image, it will show title of the combine noises.for example, title('poisson noise and speckle noise'). and also when the user uncheck the checkbox the noise is dissapear from the image. So here my current coding:
function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.jpg';'*.tif';'*.png'},'Select File');
if isequal(filename,0)|| isequal(pathname,0)
uiwait(msgbox ('User pressed cancel','please select an image') )
hold on;
else
uiwait(msgbox('User selected image sucessfully','sucess'));
hold off;
img = imread([pathname filename]);
img = img(:,:,1);
axes(handles.axes1);
imshow(img);
title('original image');
%update the handles structure with the image
handles.imgData = img;
%save the handles data
guidata(hObject,handles)
end
%check to make sure that the image data exists in handles
if isfield(handles,'imgData')
%grab the image data from handles
I = handles.imgData;
axes(handles.axes2);
imshow(img);
end
% hObject handle to pushbutton1 (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 checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
isChecked = get(hObject,'Value');
if isChecked==1
if isfield(handles,'imgData')
%grab the image data from handles
I = handles.imgData;
J = imnoise(I,'salt & pepper',0.3);
axes(handles.axes2);
imshow(J);
title('Noise type: Salt & pepper');
end
guidata(hObject, handles)
end
% hObject handle to checkbox1 (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 checkbox1
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
isChecked = get(hObject,'Value');
if isChecked==1
if isfield(handles,'imgData')
%grab the image data from handles
I = handles.imgData;
M = imnoise(I,'gaussian',0.1,0.1);
axes(handles.axes2);
imshow(M);
title('Noise type: Gaussian noise');
end
guidata(hObject, handles)
end
% hObject handle to checkbox2 (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 checkbox2
% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
isChecked = get(hObject,'Value');
if isChecked==1
if isfield(handles,'imgData')
%grab the image data from handles
I = handles.imgData;
N=imnoise(I,'localvar',0.05*rand(size(I)));
axes(handles.axes2);
imshow(N);
title('Noise type: Localvar noise');
end
guidata(hObject, handles)
end
% hObject handle to checkbox3 (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 checkbox3
% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
isChecked = get(hObject,'Value');
if isChecked==1
if isfield(handles,'imgData')
%grab the image data from handles
I = handles.imgData;
P=imnoise(I,'poisson');
axes(handles.axes2);
imshow(P);
title('Noise type: Poisson noise');
end
guidata(hObject, handles)
end
% hObject handle to checkbox4 (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 checkbox4
% --- Executes on button press in checkbox5.
function checkbox5_Callback(hObject, eventdata, handles)
isChecked = get(hObject,'Value');
if isChecked==1
if isfield(handles,'imgData')
%grab the image data from handles
I = handles.imgData;
Q = imnoise(I,'speckle', 0.3);
axes(handles.axes2);
imshow(Q);
title('Noise type: Speckle noise');
end
guidata(hObject, handles)
end
% hObject handle to checkbox5 (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 checkbox5
  2 Comments
amira fauzey
amira fauzey on 19 Sep 2016
here is my latest code,like i said earlier.I have 5 checkbox that represent 5 types of noise which is salt&pepper noise,localvar noise,gaussian noise, speckle noise and poisson noise. i want the user to be able to select multiple noise which is double noise or triple noise by clicking the checkbox and the noises will apply to the image.and after user click the checkboxes at the top of the image, it will show title of the combine noises.for example, title('poisson noise and speckle noise'). and also when the user uncheck the checkbox the noise is dissapear from the image

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 20 Sep 2016
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.
  7 Comments
amira fauzey
amira fauzey on 10 Oct 2016
Edited: amira fauzey on 10 Oct 2016
sorry again, i really need help.i want to add filter after i save my image noise using pushbutton.this is the code for filter.if user uncheck the checkbox i want the image with noise remain in the axes.
function checkbox6_Callback(hObject, eventdata, handles)
global noiseImage
applyFilter(handles);
function applyFilter(handles)
if isfield(handles,'imgData')
imgData = handles.imgData;
filterStr = '';
if get(handles.checkbox6,'Value')
filterStr = 'Average';
imgData = filter2(fspecial('average',3),imgData)/255;
end
if get(handles.checkbox7,'Value')
if ~isempty(filterStr)
filterStr = [filterStr ', '];
end
filterStr = [filterStr 'Median'];
imgData = medfilt2(imgData,[3 3]);
end
axes(handles.axes3);
noiseImage = imgData;
imshow(imgData);
title(['Filter: ' filterStr]);
end
i think maybe the line if isfield(handles,'imgData') seems like filter didnt pass through this line. Im not pretty sure , i dont know how to solve this problem. i attach my full coding too.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!