필터 지우기
필터 지우기

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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by