# How to vectorize a sequence of 2D images using matlab?

6 views (last 30 days)
Yamini Nibhanupudi on 10 Apr 2018
Answered: Dimitris Iliou on 10 Apr 2018
I am trying to vectorize a large set of 100x100 images into 10000x1 column vectors. But I realised something is wrong with my code. I was wondering if anyone could provide me with the code to vectorize 2D images?
This is the code I used for matlab:
Pics = dir([source,'*.jpg']); %where the source contains my path that holds the jpg images
for i=1:length(Pics)
Im = imread([source,Pics(n).name]); Vectorized_Pic(:,:,1) = double(reshape(image(:,:,1),10000,1)); % if an image has 3 planes Vectorized_Pic= double(reshape(image,10000,1)); %if it is a 2D image
end

Dimitris Iliou on 10 Apr 2018
In order for this code to work, you will need to correct some of the variables you are using.
Firstly, in Pics(n), what is n? Do you mean Pics(i)?
Also, what is image in the following case? Should that be Im?
Vectorized_Pic(:,:,1) = double(reshape(image(:,:,1),10000,1));
Vectorized_Pic= double(reshape(image,10000,1));
In addition, Vectorized_Pic should be a vector that you iterate through.
Vectorized_Pic(i,:) = double(reshape(Im(:,:,1),10000,1));
Vectorized_Pic(i,:) = double(reshape(Im,10000,1));
and you should also check the number of planes you have using size.
Pics = dir([source,'*.jpg']);
you should consider using imageDatastore. You can find more information on how to use it in: