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
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

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品


版本

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by