How to save image using one pushbutton
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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?
amira fauzey
2016 年 10 月 11 日
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.
Image Analyst
2016 年 10 月 11 日
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;
amira fauzey
2016 年 10 月 12 日
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?
Image Analyst
2016 年 10 月 12 日
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.
amira fauzey
2016 年 10 月 14 日
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
Walter Roberson
2016 年 10 月 15 日
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'.
amira fauzey
2016 年 10 月 15 日
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.
Walter Roberson
2016 年 10 月 15 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
