From: Donn Shull on
"Krithika Mohan" <kmohan2(a)jhu.edu> wrote in message <hutl71$fu6$1(a)fred.mathworks.com>...
> Hi,
>
> I am trying to read a sequence of images, available in a folder.I have the following error when running the code
>
> ??? Subscripted assignment dimension mismatch.
> Error in ==> imagesequencereading at 21
> images(:,:,count)=tmp;
>
> The following is the code that I used
>
> %// list all the files in some folder
> somefolder = '~Images\';
> filelist = dir(somefolder);
> images = [ ];
>
> count = 1;
> for k=3:size(filelist,1)
> %// filelist is not a folder
> if filelist(k).isdir ~= true
> fname = filelist(k).name;
> if strcmp( fname(size(fname,2)-3:size(fname,2)) ,'.tif') == 1
> tmp = imread([somefolder fname]);
> if size(tmp,3) == 3
> tmp = rgb2gray(tmp);
> %//Putting Images into buffer
> images(:,:,count)=tmp;
> count=count+1;
> images = [images tmp];
> disp([fname ' loaded']);
> end
> end
> end
> end
> It looks to be correct for me , but I do not know how to debug this. Some Ps help.


The first time through your loop images is of size 0 by 0 (ie empty) so it can'tbe indexed in the way that you have tried.

your code would probably be simpler if you used:

fileList = dir('~Images\*.tif')

then you would know in advance how many images you have and you could preallocate you buffer before entering the loop. I would guess that not all of your images are the same size so you may want to consider using a cell array for your buffer rather than a numeric array.

Good Luck,

Donn