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

조회 수: 1 (최근 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 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