Subscripted assignment dimension mismatch.

1 vue (au cours des 30 derniers jours)
primrose khaleed
primrose khaleed le 1 Juin 2014
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

Réponse acceptée

Geoff Hayes
Geoff Hayes le 1 Juin 2014
Modifié(e) : Geoff Hayes le 1 Juin 2014
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 commentaire
primrose khaleed
primrose khaleed le 1 Juin 2014
thank you the problem is solves

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by