How do I export image features matrix data to Excel for multiple images in the same folder?

10 Ansichten (letzte 30 Tage)
I have 100 image files which I need to process (Images are in the same folder). The idea is to take one image, perform pre-processing (noise removal, binarization etc.) followed by features extraction.I've used Wavelets (db1) to extract approximation & directional coefficients (horizontal, vertical and diagonal)-4 features per image.I need to store this features matrix in Excel format.How do I automate the process for 100 image files, so that I get an Excel sheet containing 100x4 entries?
if true
% clc;
%Code begins from here
clc;
clear all;
close all;
%Load current directory
myFolder = 'E:\BE Project\Devnagiri Character Recognition\test_images\trial';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
%imshow(imageArray); % Display image.
%drawnow; % Force display to update immediately.
end
a=imageArray;
%Scale to 512x512 since images are of higher resolution
a=imresize(a, [512 512]);
%RGB to gray
if size(a,3)==3
b=rgb2gray(a);
end
figure;
imshow(a);
title('Original Image')
%Noise removal by median filter
f=medfilt2(b);
figure;
imshow(f);
title('Noise removal by median filter')
%Determine threshold by Otsu's method
th=graythresh(f);
g=im2bw(f,th);
figure;
imshow(g);
title('Binarized Image (Otsu Method)')
%Resize image for Wavelet Transformation
g=imresize(g, [128 128]);
figure;
imshow(g);
title('Resized Image')
%Find wavelet coefficients using 2D Wavelet Transform
[cA,cH,cV,cD]=dwt2(g,'db1');
disp('---WAVELET FEATURES---');
%Calculate max value for approximation coefficient
disp('Approximation Coefficient (Max Value) :');
ca_max=max(mean(double(cA)));
disp((ca_max));
%Calculate max value for horizontal coefficient
disp('Horizontal Coefficient (Max Value) :');
ch_max=max(mean(double(cH)));
disp((ch_max));
%Calculate max value for vertical coefficient
disp('Vertical Coefficient (Max Value) :');
cv_max=max(mean(double(cV)));
disp((cv_max));
%Calculate max value for diagonal coefficient
disp('Diagonal Coefficient (Max Value) :');
cd_max=max(mean(double(cD)));
disp(mean(cd_max));
%Obtain features in a matrix form
ft=cat(2,ca_max,ch_max,cv_max,cd_max);
%Export features matrix to Excel sheet
xlswrite('testdata.xlsx',ft);
end

Akzeptierte Antwort

Image Analyst
Image Analyst am 5 Jan. 2013
Something like this:
numberOfResults = 42; % Whatever it is for a single image
numberOfImages = length(filenames); % Whatever...
allResults = zeros(numberOfImages, numberOfResults);
for k = 1 : numberOfImages
% Read in image into variable called thisImage.
% Analyze the image with function AnalyzeSingleImage and get results.
thisImagesResults = AnalyzeSingleImage(thisImage);
% Store results in allResults:
allResults(k, :) = thisImagesResults;
end
xlswrite(excelFullFileName, allResults);
  9 Kommentare
Devashish Tiwari
Devashish Tiwari am 22 Jul. 2022
Yeah Exactly sir, I have multiple images to do so. But, I actually wanted to know, from those multiple images, how do I call them, and how to save the tracked particles in each image. Also, How to save the excel sheets of each image?
But, to solve this problem, I needed the work of each image and then the for loop, so I started doing so.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

Walter Roberson
Walter Roberson am 5 Jan. 2013
  3 Kommentare
Walter Roberson
Walter Roberson am 5 Jan. 2013
Save the entries into a single common array. xlswrite() the array only after all 100 are done.
Ragavi Thiyagarajan
Ragavi Thiyagarajan am 27 Feb. 2020
i am also have a same problem with exporting extracted features from matlab to excel.. can explain me to .how to save the entries in a single array?

Melden Sie sich an, um zu kommentieren.


Braiki Marwa
Braiki Marwa am 9 Jan. 2018
Bearbeitet: Image Analyst am 9 Jan. 2018
i trained two-class-classification (svmtrain) with 15 features for 18 images and i have different number of objects in a single image. I want to save single .mat file of features of these images?my problem is when i run this code i have just the variables of last image!!This is my code :
NbIm = size(names1,1);
n1 = 1;
n2 = NbIm;
for n=n1:n2
%1- Read the original image
%2- Processing : Segmentation
%3- characterization :
[B3,L3,N3] = bwboundaries(ICellules); (see picture)
CC = bwconncomp(L3);
BW=bwlabel(L3); stats1=regionprops(CC,'Area','Centroid','Eccentricity','Perimeter','ConvexArea','ConvexHull','ConvexImage','MajorAxisLength','MinorAxisLength','Orientation','Solidity','BoundingBox');
for k=1:length(B3),
V=[];glcm=[];
V=Im_originale(BW==k);
glcm = graycomatrix(V,'Offset',[2 0],'Symmetric', true);
stats= graycoprops(glcm);
Contrast_Cellule =stats.Contrast;
Correlation_Cellule =stats.Correlation;
Energy_Cellule =stats.Energy;
Homogeneity_Cellule =stats.Homogeneity;
Area_cellule = stats1(k).Area;
Perimeter_cellule = stats1(k).Perimeter;
Circularity_cellule= (4*pi*Area_cellule)/Perimeter_cellule^2;
Centroid_cellule = stats1(k).Centroid;
Compactness_cellule=Perimeter_cellule^2/(4*pi*Area_cellule);
MajorAxis_cellule=stats1(k). MajorAxisLength;
MinorAxis_cellule=stats1(k). MinorAxisLength;
Orientation_cellule =stats1(k).Orientation;
Eccentricity_cellule=stats1(k).Eccentricity;
Solidity_cellule=stats1(k).Solidity;
boundary3 = B3{k};
[cc] = chaincode(boundary3);
ai=cc.code;
ai = ai.';
output = calc_harmonic_coefficients(ai,30);
Ampl=0.5*sqrt((output(1)^2)+(output(2)^2)+(output(3)^2)+(output(4)^2));
Feat(k,:)=[Area_cellule,Perimeter_cellule,Circularity_cellule,Compactness_cellule, Solidity_cellule,Eccentricity_cellule,MajorAxis_cellule,MinorAxis_cellule, Centroid_cellule,Ampl,Contrast_Cellule,Correlation_Cellule,Energy_Cellule,Homogeneity_Cellule];
end
end
  3 Kommentare
Braiki Marwa
Braiki Marwa am 10 Jan. 2018
Hi, thanks for your response...can you please explain more because i don't understand
Image Analyst
Image Analyst am 10 Jan. 2018
Actually I thought B3 was an image, but it's not, so your for loop line should also work as it.
For the line
Area_cellule = stats1(k).Area;
you're just taking the k'th area variable and assigning it to Area_cellule. So for k=1 (first iteration) Area_cellule = the first area. For k=2, Area_cellule = the second area. For the last iteration Area_cellule = the last area. And when the loop finally exits, Area_cellule is just a single number equal to the last area, NOT an array of all areas like you said you wanted. To get an array, you either have to do
Area_cellule*k( = stats1(k).Area;
inside the loop, or better, don't assign Area_cellule at all inside the loop and have this outside the loop:
Area_cellule = [stats1.Area];
Same for all the other properties of stats1 you're trying to make into individual arrays, like Perimeter_cellule etc.

Melden Sie sich an, um zu kommentieren.


anuar ibrahim
anuar ibrahim am 6 Apr. 2019
numberOfResults = 42; % Whatever it is for a single image
numberOfImages = length(filenames); % Whatever...
allResults = zeros(numberOfImages, numberOfResults);
for k = 1 : numberOfImages
% Read in image into variable called thisImage.
% Analyze the image with function AnalyzeSingleImage and get results.
thisImagesResults = AnalyzeSingleImage(thisImage);
% Store results in allResults:
allResults(k, :) = thisImagesResults;
end
xlswrite(excelFullFileName, allResults);
can u show with the code please? i dont understand

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by