creating .mat file with 100 images.

1 visualización (últimos 30 días)
ravi
ravi el 27 de Ag. de 2013
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 comentarios
Image Analyst
Image Analyst el 27 de Ag. de 2013
Is there, or is there not, a space before the left parenthesis?
Walter Roberson
Walter Roberson el 27 de Ag. de 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 ??

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 27 de Ag. de 2013
Editada: Jan el 27 de Ag. de 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 comentario
Image Analyst
Image Analyst el 27 de Ag. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Import, Export, and Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by