Subscripted assignment dimension mismatch.

조회 수: 1 (최근 30일)
primrose khaleed
primrose khaleed 2014년 6월 1일
댓글: primrose khaleed 2014년 6월 1일
hi everybody...i doing this code but i have this problem in code can any one help me plz
input_dir = 'E:\matlab\pcaimage';
image_dims = [48, 64];
filenames = dir(fullfile(input_dir, '*.jpg'));
num_images = length(filenames);
images = [];
for n = 1:num_images
filename = fullfile(input_dir, filenames(n).name);
img = imread(filename);
if n == 1
% img=reshape(img,48,64);
images = zeros(prod(image_dims), num_images);
end
images(:, n) = img(:);
end
the size of my images is 1200X900 i try to resize the images into 48X64 the problem is
Subscripted assignment dimension mismatch.
Error in eigenvector (line 14) images(:, n) = img(:);
can any one help me plz

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 6월 1일
편집: Geoff Hayes 2014년 6월 1일
The above code seems to be assuming that the images are two dimensional only. Is this a valid assumption, or are the images (or matrices) 1200x900x3?
The error message is telling you that there is dimension mismatch in your assignment at line
images(:, n) = img(:);
In this case, the code is trying to insert a vector (once the colon is used in img(:)) that is larger than the destination row of images. As you have stated, the size of any image is 1200x900 (so 1080000 elements) BUT images has only been sized a matrix with n rows and 3072=48*64 columns…which is considerably smaller than 1080000. Hence the error.
In the line prior to this assignment, there is an attempt to reshape the data which has been commented out since this line probably generated the error To RESHAPE the number of elements must not change. Since you want to resize, the code should use the imresize command instead:
img = imresize(img,[48 64]);
Using imresize will reduce the image to the 48x64 size which can then be assigned to images.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by