How can i take multiple images from a folder (which is almost 800!) and perform specific operation?

2 ビュー (過去 30 日間)
I know how to calculate entropy of a single image channels. But I want to calculate entropy for each images from a dataset, so that the output shows "what percent of images" are in some specific entropy range.
my entropy code: (I'm using MATLAB 2015b)
I= im;
Red = I(:,:,1);
Green = I(:,:,2);
Blue = I(:,:,3);
%I = I(:); % Vectorization of RGB values
p = imhist(Red); % Histogram
p(p == 0) = [ ];% remove zero entries in p
p = p ./ numel(I); % normalize p so that sum(p) is one.
Er = round(-sum(p.*log2(p)),3);
p = imhist(Blue); % Histogram
p(p == 0) = [ ];% remove zero entries in p
p = p ./ numel(I); % normalize p so that sum(p) is one.
Eb = round(-sum(p.*log2(p)),3);
figure(1),imshow(im),title(['Entropy for R channel = ', num2str(Er),', Entropy for B channel = ', num2str(Eb)]);

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 7 月 13 日
You'd need to employ for or while loop with the following loop structure:
M_FOLDER = '???\MATLAB'; % Directory where all image files are residing
F_Pattern = fullfile(M_Folder, '*.png'); % OR F_Pattern = fullfile(myFolder, '*.jpeg'); or *.tiff
FILES = dir(F_Pattern);
F_names = {FILES.name};
for jj = 1 : length(F_names)
BFileName = FILES(jj).name;
F_FileName = fullfile(FILES(jj).folder, BFileName);
I = imread(F_FileName);
...
end
  2 件のコメント
rakib mostafiz
rakib mostafiz 2021 年 7 月 20 日
編集済み: rakib mostafiz 2021 年 7 月 20 日
Thnaks for your help!
When i run, it shows an error at 2.
Undefined function or variable 'M_Folder'.
Can help me to solve this error?
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 7 月 21 日
Provide your full directory address to M_Folder
Or change the current directory to M_Folder containg all image files, e.g.:
cd C:\Users\????

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by