creating .mat file with 100 images.

4 ビュー (過去 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 Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by