Borrar filtros
Borrar filtros

How to save image using one pushbutton

1 visualización (últimos 30 días)
amira fauzey
amira fauzey el 29 de Sept. de 2016
Comentada: amira fauzey el 17 de Oct. de 2016
i add noise in image at axes2, and then i want to save the image.can anyone help me?here is my code that i try
function checkbox1_Callback(hObject, eventdata, handles)
applyNoise(handles);
function applyNoise(handles)
if isfield(handles,'imgData')
imgData = handles.imgData;
noiseStr = '';
if get(handles.checkbox1,'Value')
noiseStr = 'Salt & pepper';
JData = imnoise(imgData,'salt & pepper',0.3);
end
if get(handles.checkbox2,'Value')
if ~isempty(noiseStr)
noiseStr = [noiseStr ', '];
end
noiseStr = [noiseStr 'Gaussian'];
JData = imnoise(imgData,'gaussian',0.1,0.1);
end
if get(handles.checkbox3,'Value')
if ~isempty(noiseStr)
noiseStr = [noiseStr ', '];
end
noiseStr = [noiseStr 'localvar'];
JData = imnoise(imgData,'localvar',0.05*rand(size(imgData)));
end
if get(handles.checkbox4,'Value')
if ~isempty(noiseStr)
noiseStr = [noiseStr ', '];
end
noiseStr = [noiseStr 'poisson'];
JData = imnoise(imgData,'poisson');
end
if get(handles.checkbox5,'Value')
if ~isempty(noiseStr)
noiseStr = [noiseStr ', '];
end
noiseStr = [noiseStr 'speckle'];
JData = imnoise(imgData,'speckle', 0.3);
end
axes(handles.axes2);
%imshow(imgData);
imshow(JData)
title(['Noise type: ' noiseStr,]);
handles.JData = imgData;
%save the handles data
%guidata(hObject,handles);
end
if isfield(handles,'JData')
imgData = handles.JData;
end
and here my save button
function pushbutton2_Callback(hObject, eventdata, handles)
if isfield(handles,'JData')
imgData = handles.JData;
%if isfield(handles,'imgData')
%imgData = handles.imgData;
[Save,savename] = uiputfile('*.jpg','save this file')
fname=fullfile(savename,Save);
imwrite(imgData,fname); % where F is your image
end

Respuesta aceptada

Image Analyst
Image Analyst el 29 de Sept. de 2016
Change the declaration to return handles, like this
function handles = applyNoise(handles)
otherwise the changes you make to handles (like adding a field handles.JData) will never be seen by your other functions.
  22 comentarios
Image Analyst
Image Analyst el 15 de Oct. de 2016
OK, so are we done now? Just recall what I said about the order of the filters being applied makes a big difference!
amira fauzey
amira fauzey el 17 de Oct. de 2016
It's okay now, thanks sir :)

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by