how to open image according to the selected image

1 visualizzazione (ultimi 30 giorni)
ayushi
ayushi il 20 Lug 2016
Risposto: Walter Roberson il 24 Lug 2016
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 Commenti
Image Analyst
Image Analyst il 24 Lug 2016
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 il 24 Lug 2016
I distinctly remember having answered this same poorly-worded question twice already.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 24 Lug 2016
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