how to open image according to the selected image

2 次查看(过去 30 天)
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);

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by