필터 지우기
필터 지우기

how to open image according to the selected image

조회 수: 1 (최근 30일)
ayushi
ayushi 2016년 7월 20일
답변: Walter Roberson 2016년 7월 24일
sir @Walter Roberson and @Image analyst i am using the gui and code for selecting an image is as follows:
global im
[filename, pathname]=uigetfile( {'*.jpg';'*.jpeg';'*.gif';'*.png';'*.bmp'},'Select file');
MyImage = strcat(pathname, filename);
%This code checks if the user pressed cancel on the dialog.
if isequal(filename,0) || isequal(pathname,0)
uiwait(msgbox ('User pressed cancel','failed','modal') )
hold on;
else
hold off;
uiwait(msgbox('User selected image sucessfully','sucess','modal'));
end
im=imread(MyImage);
im=im2double(im); %converts to double
%for backup process :)
imshow(im,'Parent',handles.axes2);
as according to the following code i want to open an image present in a folder suppose the user have selected image1 then in the second section:
function pushbutton2_Callback(hObject, eventdata,handles,varargin)
global im
load abc
end
in load abc i want to code that if the user selected suppose image1 then the
figure;
imshow(image4 );
not getting how to do this please guide
  댓글 수: 5
Image Analyst
Image Analyst 2016년 7월 24일
I don't understand the question. So the user selected image1.png from the dialog box and you read it into global variable im. And then you want to display image4. What is image4??? And why did you call load() to load in the "abc.mat" file???
Walter Roberson
Walter Roberson 2016년 7월 24일
I distinctly remember having answered this same poorly-worded question twice already.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 7월 24일
Your line
MyImage = strcat(pathname, filename);
is incorrect. The path that is returned by uigetfile does not always have a directory separator at the end of it. You need to be add the directory separator character between the two. The easiest way to do that is to use fullfile() instead of strcat()
MyImage = fullfile(pathname, filename);

Community Treasure Hunt

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

Start Hunting!

Translated by