vectorizing 150 images, reshaping them and concatenating in computer vision
1 view (last 30 days)
Show older comments
I have 150 images in png format (161x261 pixels), named image001.png to image 150.png .
If I want to convert all these 150 images into data 150 data matrices, reshape them such that each image gives me a 42021x1 matrix and concatenate all 150 matrices into a 42021x150 matrix, is there a code to achieve this loop process? I am not sure how to do this as my knowledge of basic is pretty basic. Thanks.
0 Comments
Answers (1)
Dima Lisin
on 9 Feb 2015
You can read an image using the imread function. You can convert an image into a 1D array using the : operator.
% Pre-allocate the giant matrix. Use uint8 to save memory
output = zeros(161*261, 150, 'uint8');
% The main loop
for i = 1:15
% Read an image
im = imread(sprintf('image%00d.png', i));
% Convert to grayscale, assuming the image is RGB
im = rgb2gray(im);
% Copy into the giant matrix
output(i, :) = im(:);
end
0 Comments
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!