How can i put this below lines of code in a for loop?

1 vue (au cours des 30 derniers jours)
Ibrahim Ullah
Ibrahim Ullah le 11 Jan 2020
Commenté : Ibrahim Ullah le 12 Jan 2020
I = imread('img70.tif');
GLCM2 = graycomatrix(I);
stats = GLCM_Features4(GLCM2,0);
writetable( struct2table( stats ), 'single70.xlsx','Range','A1' );
type 'single70.xlsx';
I have thousands of images to take value of and put them into a single matrix, what i want to do here i want to put this code inside a for loop so that i don't have to run this code manually for each single xlcx file. Any kind of help will be highly appreciated.

Réponse acceptée

Meg Noah
Meg Noah le 12 Jan 2020
Modifié(e) : Meg Noah le 12 Jan 2020
Here's how to do it for png, because that is all I have. Change extension to tif.
% Edit this to be your toplevel directory
myDir = '';
% Edit this for the extension of image type ...
fileList = dir(fullfile(myDir,'*.png'));
myTable = table();
for ifile = 1:length(fileList)
I = imread(fullfile(myDir,fileList(ifile).name));
I = squeeze(I(:,:,1)); % my data are 3-color - edit preprocessing as needed
GLCM2 = graycomatrix(I);
stats = GLCM_Features4(GLCM2,0);
% Note: you can add more stuff about your file here like image size, etc.
stats.filename = {fileList(ifile).name};
% Append information about this image to the growing table
myTable = vertcat(myTable,struct2table( stats ));
end
% i like the filename to be first in the table
myTable = myTable(:,[end 1:(end-1)]);
% save your totally awesome results 'cause you rock and never stop!
writetable(myTable,'myAwesomeGLCMProcessing.xlsx');
  1 commentaire
Ibrahim Ullah
Ibrahim Ullah le 12 Jan 2020
Thanks a lot, though the images did not maintain order but it worked , you saved my tons of time.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by