vectorizing 150 images, reshaping them and concatenating in computer vision

1 次查看(过去 30 天)
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.

回答(1 个)

Dima Lisin
Dima Lisin 2015-2-9
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

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by