フィルターのクリア

How can I extract frequency values of intensity from multiple image files to one Excel file

1 回表示 (過去 30 日間)
Dear community,
I am trying to extract frequency values from histograms of multiple images (*.jpg) and then save data to an Excel file, using the following script.
However, it did not work. Please help me to extract data to one Excel file with data columns labled by the file name of image at first row.
Thank you very much,
// My code
path_directory='myfolder'; % 'myfolder' in my current directory
myfiles=dir([path_directory '/*.jpg']);
for k=1:length(myfiles)
filename=[path_directory '/' myfiles(k).name];
I=imread(filename);
I=rgb2gray(I);
[count,x]=imhist(I,25);
T=table(count);
writetable(T, 'frequency.xlsx');
end

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 18 日
You have done almost everything correct. However, you are over-writing the excel file with each iteration, thus you will only get the values corresponding to the final file.
You can either store data for images in separate columns -
path_directory='myfolder'; % 'myfolder' in my current directory
myfiles=dir([path_directory '/*.jpg']);
%number of files
n = numel(myfiles);
%As it is known that there are 25 bins for categorizing data, the output
%will be a 25x1 vector, thus preallocate accordingly
count = zeros(25,n);
for k=1:n
filename=[path_directory '/' myfiles(k).name];
I=imread(filename);
I=rgb2gray(I);
count(:,k)=imhist(I,25);
end
T = table(count);
writetable(T, 'frequency.xlsx');
Or you can store the data for images in separate sheets -
path_directory='myfolder'; % 'myfolder' in my current directory
myfiles=dir([path_directory '/*.jpg']);
%number of files
n = numel(myfiles);
%preallocate worksheets
writetable(table(),'frequency.xlsx','Sheet', n);
for k=1:n
filename=[path_directory '/' myfiles(k).name];
I=imread(filename);
I=rgb2gray(I);
[count,x]=imhist(I,25);
T=table(count);
writetable(T, 'frequency.xlsx', 'Sheet', k);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by