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

2 visualizzazioni (ultimi 30 giorni)
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)]);

Risposte (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov il 13 Lug 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 Commenti
rakib mostafiz
rakib mostafiz il 20 Lug 2021
Modificato: rakib mostafiz il 20 Lug 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 il 21 Lug 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\????

Accedi per commentare.

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Prodotti


Release

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by