To read Image from csv file
13 次查看(过去 30 天)
显示 更早的评论
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 个评论
DGM
2023-3-13
编辑:DGM
2023-3-13
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?
回答(1 个)
Image Analyst
2023-3-12
See attached code that puts image values into a CSV file. Adapt as needed.
To process a sequence of files, see the FAQ:
4 个评论
Image Analyst
2023-3-20
@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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Import, Export, and Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!