Matlab – How does path retrieval work using imread and imwrite


I know how imread and imwrite works, but I don't know where do the function call the image file from? In other words, where do I store the image in order to call it using imread?

Best Answer

As Adam suggests you could change the Matlab working directory to the location of your images or what I tend to do is to get the user to select the file to be read using uigetfile

>> [fn,pn]=uigetfile({'*.TIFF,*.jpg,*.bmp','Image files'}, 'Select an image');
>> I = imread(fullfile(pn,fn));

or if you know the directory of to the images you want to read you could store it in a variable then you could get a list of images in that directory using dir

>> imageDir = 'c:\path\to\my\images';
>> imageList = dir(fullfile(imageDir,'*.tif')); % store all files with extension tif  
                                               % in a structure array imageList

from there you can loop through imageList and process each image found. Finally, you can use uigetdir to ask the user for the direcotory containing the image set.