Find Images

Language: MATLAB

Last modified: 04 February 2009

The find_images function recursively searches a directory for images and creates an m-file with paths to the images. This m-file allows images to be read in a uniform way across different computers and platforms. It is also possible to associate arbitrary metadata with each image.

find_images.m

Basic usage

The simplest way to use this function is to pass it the name of a directory full of images. For examples, let’s assume you have a directory called imagedir which contains images and might have subdirectories that also contain images. To build the m-file, go to the parent directory of imagedir and type the following:

>> find_images('imagedir');

There should now be a file called imagedir.m in the current working directory which stores a struct array with paths to all the images found below imagedir. To load the struct array and read the first image, type the following:

>> files = imagedir;
>> im = imread(files(1).path); 

Advanced usage

You can optionally specify the output filename and extra fields (initialized to empty strings) in the second and third arguments as follows:

>> find_images('imagedir', 'files1.m');
>> find_images('imagedir', 'files2.m', {'ISO', 'focal'});

To make the file portable across different machines, users, or platforms, you can define an environment variable called RESEARCH that defines the path to a top level directory on a particular computer. For example, I keep my files under version control and the RESEARCH variable stores the root of the local copy of my subversion tree. For information on environment variables, type help setenv in MATLAB. You can put the setenv command in your startup.m file.

Notes

This function is a rewrite of a python script I have been using for years. The original script can also read EXIF info from images, but I rarely need this feature.

Python implementation

Updates

1/25/2009 Rewrote python script in MATLAB
2/4/2009 Small fix to allow uppercase extensions
10/17/2009 Modified script to output generic paths