To read Image from csv file

Hello,
i want to read 700 images and store them in .csv file in only one column formate then show these one column formated images into matlab.

1 Comment

DGM
DGM on 13 Mar 2023
Edited: DGM on 13 Mar 2023
If you want the a rectangular image in a single-column format, then there's no obvious way to describe what the original image geometry was. That information would either need to be in the file header, a separate header file, or simply presumed by some convention.
Given that there probably isn't a good reason to store images as CSV unless it's for sake of compatibility with some other software, then the format required by said software is something that must be known in order to create a compatible file.
So what is the required format?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 12 Mar 2023
See attached code that puts image values into a CSV file. Adapt as needed.
To process a sequence of files, see the FAQ:

4 Comments

Thank You for your response but i a beginner in matlab and i need some time to understand this.
Shouldn't take very long because it's pretty simple. So, did you understand it? Maybe you could explain why you want all the values in a CSV file.
i have a retinal images dataset with 50 diseases i want to classify them.
for this first i want to apply machine learning alogorithm on numeric data which i take from theses images by using imread function.
all this data is converted into column formate.
@Sara Ejaz so I'm guessing you got it solved with my hint and got something like this:
% Process a sequence of PNG images.
filePattern = fullfile(pwd, '*.png');
imds = imageDatastore(filePattern) % Create an image Datastore
% Get all filenames into one cell array. Filenames have the complete path (folder prepended).
allFileNames = imds.Files;
numFiles = numel(imds.Files);
for k = 1 : numel(allFileNames)
% Get this file name.
fullFileName = allFileNames{k};
fprintf('Processing %s\n', fullFileName);
% Now read in image with imread.
rgbImage = imread(fullFileName);
% Split apart into spearate color channels.
[r, g, b] = imsplit(rgbImage);
% Make into column format.
data = [r(:), g(:), b(:)];
% Create output filename for this image's CSV file.
outputFileName = strrep(fullFileName, '.png', '.csv');
% Write out the data.
writematrix(data, outputFileName);
end
If you also need x and y, see how I did it in the attached demo.
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

Sign in to comment.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Asked:

on 12 Mar 2023

Commented:

on 20 Mar 2023

Community Treasure Hunt

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

Start Hunting!