creating .mat file with 100 images.

1 次查看(过去 30 天)
ravi
ravi 2013-8-27
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 个评论
Image Analyst
Image Analyst 2013-8-27
Is there, or is there not, a space before the left parenthesis?
Walter Roberson
Walter Roberson 2013-8-27
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 ??

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2013-8-27
编辑:Jan 2013-8-27
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 个评论
Image Analyst
Image Analyst 2013-8-27
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Import, Export, and Conversion 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by