Hello Everyone,
I have a bunch of greyscale images. All are resized 50 * 50. All are located in the same folder.
I want to extract the matrix of all pixel values of the images into multipe exel spreadsheets (one sheet for each image).
How could I do it automatically for all images at once?
thanks

 採用された回答

Image Analyst
Image Analyst 2021 年 5 月 5 日

0 投票

% Specify the folder where the files live.
myFolder = 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.png'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
xlsFullFileName = fullfile(myFolder, 'Results.xlsx') % Whatever....
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
[~, sheetName, ext] = fileparts(baseFileName);
writematrix(imageArray, xlsFullFileName, sheetName);
end

1 件のコメント

Amir Nejati
Amir Nejati 2021 年 5 月 6 日
Thank you for the code.
I am receiving this error:
Error using writematrix (line 191)
Wrong number of arguments. A filename must be provided when supplying additional parameters, and each parameter name must
be followed by a value.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by