How to retrieve image name

I have loaded an image having name '1.bmp' using GUI and stored it in the variable 'im'.Is there a way I can get the filename/image name? I want to do something like this
if ( name(im)='1.bmp')
statement1
elseif (name(im)='2.bmp')
statement2
else
statement 3
And so on? Please help me. I am a beginner. % code end

Respuestas (2)

Image Analyst
Image Analyst el 8 de Dic. de 2017

0 votos

You need to save the filename string and be able to access it in other functions.
John D'Errico
John D'Errico el 8 de Dic. de 2017

0 votos

Having loaded an image into a variable, the original name of the image in the file it was stored in is NOT carried along.
Nothing stops you from retaining that name in a different variable. Or you might even decide to name the image variable in a way that was consistent with the filename, although you cannot name a variable with purely a number. So 1 is not a valid variable name, nor can you start the name of a variable with a number.

3 comentarios

Suraj Suresh
Suraj Suresh el 8 de Dic. de 2017
this is the code I used to load the image
global im im2
[path,user_cance]=imgetfile();
im=imread(path);
Is there a way that I can get the filename of the image, say 'imgname.bmp', store it in a string variable say 'string sname' and then
strcmp(sname,'imgname.bmp');
if true
statement1
else
statement2
end
How can I do this or any similar way?
Stephen23
Stephen23 el 8 de Dic. de 2017
Editada: Stephen23 el 8 de Dic. de 2017
  1. Do not use path as a variable name, because this is the name of a very important inbuilt function.
  2. The first output of imgetfile is the full path: split this into the filename and pathname using fileparts.
  3. compare using strcmpi, not strcmp (unless you are using a case-sensitive OS).
Suraj Suresh
Suraj Suresh el 8 de Dic. de 2017
You, Sir, are the best. It worked. Thanks a million. Finally. It is really ironic that I did all the complicated stuff like segmentation, clearing noise, dilation etc. easily but got stuck in a small thing like retrieving the name of the loaded image. Thank you.

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Preguntada:

el 8 de Dic. de 2017

Comentada:

el 8 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by