How to populate csv rows, rather than columns? This program creates a csv file with each vectorized image in a column, but i want to know if it's possible to store each vectorized image as a row instead.

myDir = 'imgs2';
f = fullfile(myDir, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(f);
vector_imag = zeros(28^2, length(theFiles ));
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imag = imread(fullFileName); %reads image
imag_gray = rgb2gray(imag); %turns image to grayscale
imag_28 = imresize(imag_gray, [28 28]); %resizes image
vector_imag(:,k) = imag_28(:); %vectorizes the image
end
csvwrite('imgdata.csv', vector_imag); %writes vectorized image to csv file

 Réponse acceptée

It seems trivial to resolve to me:
Either tranpose your matrix when you write it:
csvwrite('imgdata.csv', vector_imag');
Or store the images in the rows of your matrix instead of the columns:
vector_imag = zeros(length(theFiles), 28^2);
for k = 1 : length(theFiles)
%...
vector_imag(k,:) = imag_28(:); %vectorizes the image
end
csvwrite('imgdata.csv', vector_imag);

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by