이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How can i read images for filtering using if else condition in GUI?
조회 수: 1 (최근 30일)
이전 댓글 표시
function popupmenu3_Callback(hObject, eventdata, handles)
popupimage=get(popupmenu3.handles,'value');
img=imread('flower.jpg');
img1=imread('balloon.jpg');
%average
if
popupimage==img
e=fspecial('average',[33])
A=imfilter(img,e);
axes(handles.axes2);
imshow(A);
else if popupimage==img1
e=fspecial('average',[33])
B=imfilter(img1,e);
axes(handles.axes2);
imshow(B);
end
채택된 답변
Image Analyst
2014년 12월 5일
Try this:
selectedItem = get(popupmenu3.handles,'value');
img=imread('flower.jpg');
img1=imread('balloon.jpg');
%average
e=fspecial('average',[33])
axes(handles.axes2);
if selectedItem == 1
A=imfilter(img,e);
imshow(A);
elseif selectedItem == 2
B=imfilter(img1,e);
imshow(B);
end
댓글 수: 16
siti
2014년 12월 5일
thanks for your answer.i can read the image but,why i still cannot filter the image?
Image Analyst
2014년 12월 5일
You have to give me more information, because when I selected an item number, and used standard MATLAB demo images, it worked just fine:
selectedItem = 2; % get(popupmenu3.handles,'value');
img=imread('onion.png');
img1=imread('cameraman.tif');
%average
e=fspecial('average',[33])
% axes(handles.axes2);
if selectedItem==1
A=imfilter(img,e);
imshow(A);
elseif selectedItem==2
B=imfilter(img1,e);
imshow(B);
end
Does the code above work for you? If so, investigate why your is different.
Image Analyst
2014년 12월 5일
Siti's "Answer" moved here:
thanks again,now i can do the filtering process..but sometimes the output showing the different image. Actually what i'm trying to do is to read the images from files
function Graybutton_Callback(hObject, eventdata, handles)
path='G:\IP.projek\grayImg';
filter='*.jpg';
selectedFile=uigetfile(fullfile(path, filter));
axes(handles.axes1);
imshow(selectedFile);
function ColorButton_Callback(hObject, eventdata, handles)
path='G:\IP.projek\color img';
filter='*.jpg';
selectedFile=uigetfile(fullfile(path, filter));
axes(handles.axes1);
imshow(selectedFile);
and then i choose flower image in color img folder for example,then i want to apply filtering process.Currently i'm using popup menu for the list of filters .So now i'm just a little bit confuse.does i need to use switch case for every filter that i'm going to use? And in every case should i put if else condition for different images that i'm going to filter?.if yes,how to do it? i'm sorry for asking this but i really don't know.
Image Analyst
2014년 12월 5일
No. You should have a listbox that you load up with image names. Then you can have a listbox or popup that you load up with filter names. In the callback of each control, you should call a function called FilterSelectedImage(handles) that you write. Inside FilterSelectedImage() you get the string and value of the listbox, then read in the selected image into a variable in that function. Then you get the value of the filter listbox or popup. You have a switch or if to filter the image according to the different filter types, then display it of course. This way no matter which you click on - the image file name, or the filter name - you will read in an original image and perform the filter on it.
siti
2014년 12월 7일
i try to use listbox to load the image.but i got error..whats wrong with my code?
function listboxImg_Callback(hObject, eventdata, handles)
img = get(handles.listboxImg, 'Value');
if(img==1)
A=imread('flower.jpg');
axes(handles.axes1);
imshow(A);
elseif(img==2)
B=imread('balloon.jpg');
axes(handles.axes1);
imshow(B);
elseif(img==3)
C=imread('Grayflower.jpg');
axes(handles.axes1);
imshow(C);
elseif(img==4)
D=imread('Grayballoon.jpg');
axes(handles.axes1);
imshow(D);
end
Image Analyst
2014년 12월 7일
You don't need any of that. In your callback, just have this:
% Get selected index.
selectedItem = get(handles.listboxImg, 'Value');
% If more than one is selected, bail out.
if length(selectedItem) > 1
return;
end
% If only one is selected, display it.
% First you need to get a list of all the items in the listbox.
ListOfImageNames = get(handles.lstImageList, 'string');
% Now construct the filename.
baseImageFileName = cell2mat(ListOfImageNames(selectedItem));
fullImageFileName = [handles.imageFolder '\' baseImageFileName]; % Prepend folder.
% Now read in the image.
rgbImage = imread(fullImageFileName);
% Now display the image.
axes(handles.axes1);
imshow(rgbImage);
title(baseImageFileName, 'FontSize', 20);
Image Analyst
2014년 12월 7일
siti's "Answer" moved here since it contains another question and appears not to be a final answer to the original question, but a reply to me.
Thanks,i already use this coding.
function LoadImg_Callback(hObject, eventdata, handles)
% hObject handle to LoadImg (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
contents = get (handles.listbox1,'Value');
switch contents
case 1
A=imread('flower.jpg');
axes(handles.axes1);
imshow(A);
case 2
A=imread('balloon.jpg');
axes(handles.axes1);
imshow(A);
case 3
A=imread('Grayflower.jpg');
axes(handles.axes1);
imshow(A);
case 4
A=imread('Grayballoon.jpg');
axes(handles.axes1);
imshow(A);
end
And i wanna ask.how can i get images from listbox to be filter in popup menu?i dont know how to write the code so that all the images in listbox can be used to filter in popup menu.
Image Analyst
2014년 12월 7일
편집: Image Analyst
2014년 12월 7일
It looks like you ignored my recommendations and went ahead with your prior code. Not sure why you didn't like my code.
Anyway, what do you have? A listbox with image names, and a popup with filter names, or what? Please attach your m and fig files or a screenshot. Do you want the user to click on an image name in the listbox and a filter showing in the popup will automatically be applied and the resulting image displayed in the axes?
siti
2014년 12월 7일
i'm sorry.it is not that i don't like your code.i'm try to figure out my coding,and i got it before you reply that comment.
yes.i have image names in listbox and filter names in popup.so when user click average filter for example,it will apply to any images that user choose in listbox.
Image Analyst
2014년 12월 7일
First try this. Have the callbacks of both the listbox and the popup call the same function called DisplayAndFilterImage. Nothing else, just simple a line like this:
DisplayAndFilterImage(handles)
Now define that function like this:
function DisplayAndFilterImage(handles)
% Get selected listbox index.
selectedItem = get(handles.listboxImg, 'Value');
% If more than one is selected, bail out.
if length(selectedItem) > 1
return;
end
% If only one is selected, display it.
% First you need to get a list of all the items in the listbox.
ListOfImageNames = get(handles.lstImageList, 'string');
% Now construct the filename.
baseImageFileName = cell2mat(ListOfImageNames(selectedItem));
fullImageFileName = [handles.imageFolder '\' baseImageFileName]; % Prepend folder.
% Now read in the image.
rgbImage = imread(fullImageFileName);
% Now display the image in axes1.
axes(handles.axes1);
imshow(rgbImage);
title(baseImageFileName, 'FontSize', 20);
% Now get what filter they chose.
selectedPopupIndex = get(handles.popup1, 'Value');
axes(handles.axes2); % We'll show result in axes 2.
switch selectedPopupIndex
case 1
% Median filter, or whatever.
filteredImage = medfilt2(rgbImage);
imshow(filteredImage);
case 2
% Your own custom filter, or whatever.
filteredImage = MyFilter(rgbImage);
imshow(filteredImage);
end
siti
2014년 12월 8일
fullImageFileName = [handles.imageFolder '\' baseImageFileName];
for this coding,imageFolder is a folder that i created for my images right?
and then
function DisplayAndFilterImage(handles)
where should i put it?is it in both listbox and popup callback?
Image Analyst
2014년 12월 8일
That looks like old code. Now I use code like this:
fullImageFileName = fullfile(handles.imageFolder, baseImageFileName);
Yes, handles.imageFolder is whatever folder you have your images in.
You put DisplayAndFilterImage() elsewhere in your file, like down at the bottom, as the last function.
siti
2014년 12월 8일
why i got this error 'Reference to non-existent field 'images'. ' ? when i use this :
baseImageFileName = cell2mat(ListOfImageNames(selectedItem));
fullImageFileName = fullfile(handles.images, baseImageFileName);
whats wrong with my code?
Image Analyst
2014년 12월 8일
You need to give it the folder with your images in it. If you didn't store the image folder string attached to your handles structure, then where are you storing it?
siti
2014년 12월 8일
i already store my images in the folder..but why it gives me this 'Reference to non-existent field 'images'. 'error?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)