MATLAB: I have 100 images in a folder ,i want to extra the features glcm ,the code reads all the images but only returns features for one image,and i want to save fin excel for later do classification can someone help

image processing

clc;
clear; close all;
% Specify the folder where the files live.
myFolder = 'C:\Users\nazem_000\Desktop\fotos\healthy';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, 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()
A= imread(fullFileName);
% segment the entire fruit
[BW,maskedRGBImage] = createMask2(A);
% color image
[BWfilled,properties] = filterRegions2(BW);
%%



% segment defect
[BWd,df] = segmentImage21(maskedRGBImage);
% defect properties
statsd = regionprops(BWd, 'Area');
statsF = regionprops(BWfilled, 'Area');
AreaD = cat(1,statsd.Area);
AreaF = cat(1,statsF.Area);
percDef = 100*AreaD/AreaF;
%%
% featureextraction (texture)
% Create the Gray Level Cooccurance Matrices (GLCMs)

gray = rgb2gray(A);
% Create the Gray Level Cooccurance Matrices (GLCMs)
glcms = graycomatrix(gray);
% Derive Statistics from GLCM
stats = graycoprops(glcms,'Contrast Correlation Energy Homogeneity');
Contrast = stats.Contrast;
Correlation = stats.Correlation;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
%%
% featureextraction (color)
Mean = mean2(maskedRGBImage);
Standard_Deviation = std2(maskedRGBImage);
Entropy = entropy(maskedRGBImage);
RMS = mean2(rms(maskedRGBImage));
%%
% feature variables
Ex = [Contrast Correlation Energy Homogeneity Mean Standard_Deviation Entropy RMS];
% Display image.
drawnow; % Force display to update immediately.
xlswrite('C:\Users\nazem_000\Desktop\fotos\healthy\healthy1.xls',Ex)
end

Best Answer

You need to specify the row in the workbook to write it to, otherwise it will always go into A1.
worksheetName = 'Results';
cellReference = sprintf('A%d', k);
xlswrite('C:\Users\nazem_000\Desktop\fotos\healthy\healthy1.xls', Ex, worksheetName, cellReference);
But it's better to do it like in your other question where you just build up the Ex matrix in the loop and write to Excel outside the loop with only a single call to xlswrite().