Some Useful Matlab Commands

MATLAB or matrix laboratory is a numerical computing environment and fourth-generation programming language[1], accourding to wikipedia.org. MATLAB allows matrix manipulations, plotting of functions and data, implemetation of algorithms, creation of user interface and interfacing with programs written in other languages[1]. MATLAB is primarily intended for numerical computing.

I worked in MATLAB for about a year during my Bachelor’s in Computer Engineering course. MATLAB was our main tool of our project IRIS (IRIS Recognition & Identification System). IRIS is a system for recogintion and identification of a person using his/her iris, which is a biometric process of recognition. During the course of the project some very useful codes were found. Some of those are as below:

i) When working on the IRIS project in MATLAB, we had to deal with huge images of the eye. The images were of huge resolution. In our case, we used images of 320×280 resolution. These are seemingly small images, however, when processing in MATLAB took a lot of time and when we had to process two images one after the another, it took us more time. In our project, we had to find the radii and centers of the iris and pupil from the eye image. Our code for this purpose took a lot of time to process.

To process the images faster and also give an output quickly, a MATLAB formatted binary file (MAT-file) was created, in which we stored the various variables that required more processing time than other. This MAT-file was called whenever the images were used the variables present in these MAT-files were used instead of re-processing the images, thus saving time. For this purpose, the “save” command was used. The common syntax for the “save” command is:

save(filename);

stores all variables from the current workspace in a MATLAB formatted binary file (MAT-file) called filename.

save(filename, variables);

stores only the specified variables. For example:

path='matfiles\';
savefile = [path, 'samplematfile-houghpara.mat'];
[circleiris, circlepupil, imagewithnoise, cropeyeimage] = segmentiris(image);
save(savefile,'circleiris','circlepupil','imagewithnoise','cropeyeimage');

Here, “[circleiris, circlepupil, imagewithnoise, cropeyeimage] = segmentiris(image);” is the function from our project that processes the images for radii and centers of the iris and pupil from the eye image, which took time to process.

The command “save(savefile,’circleiris’,’circlepupil’,’imagewithnoise’,’cropeyeimage’);“, stored the variables circleiris, circlepupil, imagewithnoise and cropeyeimage in the file ‘samplematfile-houghpara.mat’.

ii) The IRIS project required a lot of rigorous testing for calculation of the threshold values and also to find the images for approval or rejection. This required processing and calculation of Hamming Distances of various pairs of eye images, with a huge amount of output data, which were difficult to keep track of. These values of Hamming Distance were stored in an xls or excel file for tracking. Initially, we copy pasted or typed the values one by one, processing one pair of eye images at a time.

This storing of value was later made easy by the command “xlswrite“. The common syntax for the “xlswrite” is:

xlswrite(filename,A);

writes array A to the first worksheet in Excel file filename, starting at cell A1. For example:

h=[1 2 3 4 5] xlswrite('test.xls', h');
xlswrite('test.xls', h);

iii) One thing that was needed for the IRIS project was a database, which because of time constraints could not be created. For the database purpose, we used a flat file system, where we kept all the files/images required by us in a folder and read each and every file from that folder. This worked very appropriately for our project requirements, as the removal of one image/data from the data folder did not result in a “File Not Found” error. This was achieved by the command “numel“. The common syntax for “numel” is:

n = numel(A);

returns the number of elements, n, in array A.

path='images\';
files=dir([path,'*.jpg']);
numel(files);

Here, path is the current directory of the files to be searched. We can use an absolute as well as a relative path, and the path has to end with a “\”. The above code shows the number of jpg files present in the folder. Here “numel(files)” returns the number of elements in the array ‘files’.

Now, to load all the files from the folder for manipulation or storage, we can just run the for loop in matlab from 1 to numel(files) thus reading/loading all the files present in the folder.

for i=1:numel(files)
     files(i).name;
end

These are a few commands that helped a lot while coding for and the successful completion of the project IRIS.
1. http://en.wikipedia.org/wiki/MATLAB
2. http://www.mathworks.com/help/techdoc/ref/f16-6011.html

Add a Comment

Your email address will not be published. Required fields are marked *