creating .mat file with 100 images.
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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
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
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 Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!