Pixel values from multiple images
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Amir Nejati
le 5 Mai 2021
Commenté : Amir Nejati
le 6 Mai 2021
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
0 commentaires
Réponse acceptée
Image Analyst
le 5 Mai 2021
% 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!