How to save image using one pushbutton
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
채택된 답변
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
amira fauzey
2016년 10월 5일
i try to make changes to my code,certain noise that i apply to image and save it,i check on my folder it successfully save the image with noise ,and certain noise when i save it and check at my folder,it show ori image without noise.i dont know how to solve my problem.here is my code
Image Analyst
2016년 10월 6일
I'm traveling in Washington D.C. this week so I may not get to it, but attach your .fig file also so people can run your code.
amira fauzey
2016년 10월 10일
hello image analyst, i can save the image now. but right now i have problem to add filter
Image Analyst
2016년 10월 10일
I've read your comment/announcement.
amira fauzey
2016년 10월 11일
can you help me please.... i really dont know how to solve my problem.
Walter Roberson
2016년 10월 11일
You need to explain what your current problem is. What error message are you observing when you add a filter? What is your code for that section?
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 problem is the line if isfield(handles,'imgData') seems like filter didnt pass through this line. I am not pretty sure , i dont know how to solve this problem. i attach my full coding too. i really hope that you can help me.
If you want the noise image, you need to show it, not the median filtered image. You're filtering it and then assigning the smoothed, filtered image to the same variable, thus overwriting your original, noisy data. You need to assign it to a new variable. Like:
filteredImage = filter2(fspecial('average',3),imgData)/255;
is it like this? i dont know if i'm doing it right
function checkbox6_Callback(hObject, eventdata, handles)
global noiseImage
%applyFilter(handles);
%function applyFilter(handles)
if isfield(handles,'imgData')
imgData = handles.imgData;
noiseImage = handles.imgData;
filterStr = '';
if get(handles.checkbox6,'Value')
filterStr = 'Average';
filteredImage = filter2(fspecial('average',3),imgData)/255; end
if get(handles.checkbox7,'Value')
if ~isempty(filterStr)
filterStr = [filterStr ', '];
end
filterStr = [filterStr 'Median'];
filteredImage = medfilt2(imgData,[3 3]);
end
axes(handles.axes3);
% noiseImage = imgData;
imshow(noiseImage );
title(['Filter type: ' filterStr]);
end
when i unchecked the checkbox, i want the noise before i add filter remain,how to do it?
Replace that with these 3 functions:
function checkbox6_Callback(hObject, eventdata, handles)
CheckBoxClicked(handles);
function checkbox7_Callback(hObject, eventdata, handles)
CheckBoxClicked(handles);
function CheckBoxClicked(handles)
global noiseImage
fontSize = 13;
% If noiseImage is not there, see if you can get it from handles.
if isempty(noiseImage)
if isfield(handles,'imgData')
noiseImage = handles.imgData;
else
warningMessage = sprintf('WARNING: noiseImage not defined yet!');
uiwait(warndlg(warningMessage));
return;
end
end
filterName = 'None';
% Initialize to original, noisy image.
% If no checkboxes are checked, this is what will display.
filteredImage = noiseImage;
% Now examine checkboxes to see if they want one of the filters.
if get(handles.checkbox6,'Value')
% Checkbox 6 is checked so do an average.
filterName = 'Average';
kernel = ones(3)/9;
filteredImage = conv2(double(noiseImage), kernel, 'same');
elseif get(handles.checkbox7,'Value')
% Checkbox 7 is checked so do a median filter.
filterName = 'Median';
filteredImage = medfilt2(noiseImage, [3, 3]);
end
axes(handles.axes3);
imshow(filteredImage, []);
caption = sprintf('Filter type = %s', filterName);
title(caption, 'FontSize', fontSize);
If you're using "end" to finish off your function definitions, then add ends. It's optional but if you do it for one function you need to do it for all of them. They either all have ends or they all do not have ends. You can't mix styles.
amira fauzey
2016년 10월 13일
thank you so much image analyst, result come correctly
amira fauzey
2016년 10월 14일
편집: amira fauzey
2016년 10월 14일
how to make user can add more then one filter at a time?
Image Analyst
2016년 10월 14일
Replace the if/elseif construct with a bunch of separate if's. That way it can do more than 1. But I hope you know that filters are not commutative. Filtering an image with filter1 followed by filter2 will give a different image than filtering first with filter2, then filter1.
if get(handles.checkbox6,'Value')
% Checkbox 6 is checked so do an average.
filterName = 'Average';
kernel = ones(3)/9;
filteredImage = conv2(double(noiseImage), kernel, 'same');
end
if get(handles.checkbox7,'Value')
% Checkbox 7 is checked so do a median filter.
filterName = 'Median';
filteredImage = medfilt2(noiseImage, [3, 3]);
end
is it like this?
Image Analyst
2016년 10월 14일
No. And it would depend it you want to keep separate output images, or if you want them to be cascaded, like the output of one filter goes into the input of the other filter.
amira fauzey
2016년 10월 14일
편집: amira fauzey
2016년 10월 14일
i want it to be cascaded,like you said output of one filter goes into the input of the other filter.Like the combination of filters applied in the same noise image.after user click the checkboxes at the top of the image, it will show title of the combine filters.for example, Filter type = Average,Median
filteredImage = double(noiseImage);
applied_filters = {'Noise'};
if get(handles.checkbox6,'Value')
% Checkbox 6 is checked so do an average.
filterName = 'Average';
kernel = ones(3)/9;
filteredImage = conv2(filteredImage, kernel, 'same');
applied_filters{end+1} = 'Average';
end
if get(handles.checkbox7,'Value')
% Checkbox 7 is checked so do a median filter.
filterName = 'Median';
filteredImage = medfilt2(filteredImage, [3, 3]);
applied_filters{end+1} = 'Median';
end
imshow(filteredImage, 'Parent', handles.axes3);
filt_list = strjoin(applied_filters, ', ');
title(filt_list, 'Parent', handles.axes3);
amira fauzey
2016년 10월 15일
편집: amira fauzey
2016년 10월 15일
when i click the checkboxes, axes3 become white blank, and i get an error ??? Undefined function or method 'strjoin' for input arguments of type 'cell'.
i have edited the code to this,i change strjoin to horzcat
filteredImage = double(noiseImage);
applied_filters = {'Filter'};
if get(handles.checkbox6,'Value')
% Checkbox 6 is checked so do an average.
filterName = 'Average';
kernel = ones(3)/9;
filteredImage = conv2(double(noiseImage), kernel, 'same');
applied_filters{end+1} = 'Average';
end
if get(handles.checkbox7,'Value')
% Checkbox 7 is checked so do a median filter.
filterName = 'Median';
filteredImage = medfilt2(noiseImage, [3, 3]);
applied_filters{end+1} = 'Median';
end
axes(handles.axes3);
imshow(filteredImage, []);
filt_list = horzcat(applied_filters, ', ');
title(filt_list, 'Parent', handles.axes3);
not sure if correct, when i add two filter it look like it does reduce the noise.
strjoin was introduced in R2013a . You can use
filt_list = sprintf('%s, ', applied_filters{:});
filt_list = filt_list(1:end-2); %trim off final ', '
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!
amira fauzey
2016년 10월 17일
It's okay now, thanks sir :)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
