how to select image from a particular folder

i wanted to select an image from a folder named dataset....
[filename pathname]=uigetfile('*.tif','Select An Image');
when i do so, i have to select the Dataset folder and then the image from it.... what shud i do so that on execution itself the images will be displayed so that i neednt select on Dataset folder and then images

 Accepted Answer

Read the documentation.
FilterSpec can include a path. That path can contain '.','..', \, '/', or '~'. For example, '../*.m' lists all code files in the folder above the current folder.

9 Comments

sir this is my path..... % C:\Users\user\Desktop\Desktop Folder\ProjectWork\Full_Project\Coding\Dataset
i did like this
[filename pathname]=uigetfile('..\Dataset_Iris\*.png');
irisImage=imread([pathname filename]);
but it is not opening Dataset folder..... it shows the Full_Project folder...... please do reply sir..
how to make the change sir.... please do reply....
Which part of your uigetfile() call is the FilterSpec ? Change that part.
i'm not getting sir.... i did like this....
[FileName,PathName,FilterIndex] = uigetfile('FilterSpec','Dataset/*.png');
irisImage=imread([FileName PathName]);
What directory are you cd'd to at the time you run the uigetfile() ? What directory do you want to look in for the images?
C:\Users\user\Desktop\Desktop Folder\ProjectWork\Full_Project\Coding\Dataset.....
sir this is the path....
Dataset folder contains images.... i want those images to be opened in that window which gets opened to select an image.....
uigetfile() will not open images though if you're using Windows, you can tell it to show images as thumbnails (mini-images). Otherwise, adapt your code like:
folder = 'C:\Users\user\Desktop\Desktop Folder\ProjectWork\Full_Project\Coding\Dataset';
filePattern = fullfile(folder, '*.png';
[FileName,PathName,FilterIndex] = uigetfile(filePattern );
thank u sir... that was what i wanted exactly.... but if i copy the ProjectWork folder to another location... the path changes..... is it possible to do by coding.... even if i change the location of my "ProjectWork" folder i obtain the above result as u showed......
ProjectWork\Full_Project\Coding\Dataset'..... this remains the same..... can i do anything sir...
You can search your entire filesystem to try to find ProjectWork
Or, you can answer my earlier question "What directory are you cd'd to at the time you run the uigetfile() "
What I do in that case (the folder you were expecting, say the folder you used last time you ran the program, cannot be found) is to bring up a file browse dialog box, like uigetdir() or uipickfiles, and have the user locate it.

Sign in to comment.

More Answers (1)

[filename pathname]=uigetfile('*.tif','Select An Image');

Community Treasure Hunt

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

Start Hunting!