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.
  1 件のコメント
primrose khaleed
primrose khaleed 2014 年 6 月 1 日
thank you the problem is solves

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by