How to save image using one pushbutton
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Image Analyst
2016-9-29
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 个评论
Image Analyst
2016-10-15
OK, so are we done now? Just recall what I said about the order of the filters being applied makes a big difference!
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!