creating .mat file with 100 images.
1 view (last 30 days)
Show older comments
hi this ravi,
_I am trying to create .mat file for using that as a positive sample for train cascade detector process.The .mat file is to be created with images of name 1(1).jpg,1(2).jpg,....upto 1(100).jpg (all the images are rgb images) and to do so, i have written a code like this_
img = imread('1(1).jpg')
img = rgb2gray(img);
[r,c]= size(img);
h = NaN(r,c,5); %pre-allocate memory
h(:,:,1) = img;
for k=2:100
h(:,:,k) = rgb2gray(imread(sprintf('1 (%d).jpg',k)));
end
save filename cars
for this code i am getting '*Subscripted assignment dimension mismatch*' error
So please any one tell me what is the problem with the code and what is the write way to create a .mat file with these images.
thanks in advance for all who will help me.
2 Comments
Walter Roberson
on 27 Aug 2013
According to http://www.mathworks.co.uk/matlabcentral/answers/85730-comparing-an-image-with-mat-file-with-100-images you have now created a .mat file with 100 images, but you have not marked this question as completed ??
Answers (1)
Jan
on 27 Aug 2013
Edited: Jan
on 27 Aug 2013
You can use the debugger to find the source of the problems. Either set a breakpoint in the line, which causes the troubles (btw. it is useful to show the complete error message in the forum), or type:
dbstop if error
and run the code again. Then you can inspect the local variables, when Matlab stops at the error e.g. by typing in the command window:
sprintf('1 (%d).jpg',k) % Is the space between 1 and ( correct??
Img = imread(sprintf('1 (%d).jpg',k));
size(Img)
size(h)
Perhaps you will find out, that the images have different sizes, such that they cannot be stored in a 3D array directly.
1 Comment
Image Analyst
on 27 Aug 2013
That's what I thought when I looked at his very non-robust code. One more thing he can do to make it more robust is to construct the full filename on a separate line with fullfile(), then use exist(fullFileName, 'file') to check that the file actually exists before he tries to read it in (see my comment on his original question). Next, he's not even saving h into the mat file - he's saving cars (some other variable) - which is kind of strange.
See Also
Categories
Find more on Import, Export, and Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!