vectorizing 150 images, reshaping them and concatenating in computer vision
조회 수: 2 (최근 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.
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!