Home > cellorganizer > utilities > ml_loadimage.m

ml_loadimage

PURPOSE ^

ML_LOADIMAGE Read images under one directory into a 3D matrix.

SYNOPSIS ^

function [img,imgfiles]=ml_loadimage(imgdir,ext,loadthre)

DESCRIPTION ^

ML_LOADIMAGE Read images under one directory into a 3D matrix.
   IMG = ML_LOADIMAGE(IMGDIR,EXTENSION) returns a 3D matrix IMG by reading
   images with extension EXTENSION from the directory IMGDIR. The image files
   are sorted by their number labels before reading.

   IMG = ML_LOADIMAGE(MGDIR,EXTENSION,LOADTHRESHOLD) set all values greater
   than LOADTHRESHOLD to 0 in the 3D matrix. 
   ML_LOADIMAGE(MGDIR,EXTENSION,[]) is the same as 
   ML_LOADIMAGE(IMGDIR,EXTENSION).

   [IMG,IMGFILES] = ML_LOADIMAGE(...) also returns sorted file names in
   a cell array IMGFILES.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [img,imgfiles]=ml_loadimage(imgdir,ext,loadthre)
0002 %ML_LOADIMAGE Read images under one directory into a 3D matrix.
0003 %   IMG = ML_LOADIMAGE(IMGDIR,EXTENSION) returns a 3D matrix IMG by reading
0004 %   images with extension EXTENSION from the directory IMGDIR. The image files
0005 %   are sorted by their number labels before reading.
0006 %
0007 %   IMG = ML_LOADIMAGE(MGDIR,EXTENSION,LOADTHRESHOLD) set all values greater
0008 %   than LOADTHRESHOLD to 0 in the 3D matrix.
0009 %   ML_LOADIMAGE(MGDIR,EXTENSION,[]) is the same as
0010 %   ML_LOADIMAGE(IMGDIR,EXTENSION).
0011 %
0012 %   [IMG,IMGFILES] = ML_LOADIMAGE(...) also returns sorted file names in
0013 %   a cell array IMGFILES.
0014 
0015 % Copyright (C) 2006  Murphy Lab
0016 % Carnegie Mellon University
0017 %
0018 % This program is free software; you can redistribute it and/or modify
0019 % it under the terms of the GNU General Public License as published
0020 % by the Free Software Foundation; either version 2 of the License,
0021 % or (at your option) any later version.
0022 %
0023 % This program is distributed in the hope that it will be useful, but
0024 % WITHOUT ANY WARRANTY; without even the implied warranty of
0025 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0026 % General Public License for more details.
0027 %
0028 % You should have received a copy of the GNU General Public License
0029 % along with this program; if not, write to the Free Software
0030 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0031 % 02110-1301, USA.
0032 %
0033 % For additional information visit http://murphylab.web.cmu.edu or
0034 % send email to murphy@cmu.edu
0035 
0036 %   ??-???-???? Initial write TINGZ
0037 %   01-NOV-2004 Modified TINGZ
0038 %       - add comments
0039 %   15-MAR-2004 Modified TINGZ
0040 %       - get strictly increasing file numbers
0041 %   Copyright (c) Murphy Lab, Carnegie Mellon University
0042 
0043 if nargin<2
0044     error('2 or 3 arguments are required.');
0045 end
0046 
0047 if nargin<3
0048     loadthre=[];
0049 end
0050 
0051 imgfiles=ml_dir([imgdir '/*.' ext]);
0052 
0053 if(isempty(imgfiles))
0054     img=[];
0055     imgfiles={};
0056     return;
0057 end
0058 
0059 pos=1;
0060 
0061 for i=1:length(imgfiles)
0062     filenum(i)=ml_getfilenum(imgfiles{i});
0063 end
0064 [sorted,num]=sort(filenum);
0065 
0066 if length(sorted)>0
0067     while any(sorted(1:end-1)-sorted(2:end)==0) & all(num>0)
0068         pos=pos+1;
0069         for i=1:length(imgfiles)
0070             filenum(i)=ml_getfilenum(imgfiles{i},pos);
0071         end
0072         if any(filenum<0)
0073             break
0074         else
0075             [sorted,num]=sort(filenum);
0076         end
0077     end 
0078 end
0079 
0080 imgfiles=imgfiles(num);
0081 
0082 for i=length(imgfiles):-1:1
0083     img(:,:,i)=ml_readimage([imgdir '/' imgfiles{i}]);
0084 end
0085 
0086 if ~isempty(loadthre)
0087     img(find(img > loadthre)) = 0;
0088 end

Generated on Sun 29-Sep-2013 18:44:06 by m2html © 2005