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

2 views (last 30 days)
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)]);

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 13 Jul 2021
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 Comments
rakib mostafiz
rakib mostafiz on 20 Jul 2021
Edited: rakib mostafiz on 20 Jul 2021
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 on 21 Jul 2021
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\????

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!