vectorizing 150 images, reshaping them and concatenating in computer vision

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

Dima Lisin
Dima Lisin il 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

Categorie

Scopri di più su Dimensionality Reduction and Feature Extraction in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by