简体   繁体   English

从文件夹中获取多张图像并在MATLAB中执行特定操作

[英]Taking multiple images from a folder and perform specific operation in MATLAB

I know how to calculate the entropy of a single image channel.我知道如何计算单个图像通道的熵。 But I want to calculate entropy for each image from a dataset (almost 800), so that the output shows "what percent of images" are in some specific entropy range.但是我想计算数据集(近 800 个)中每个图像的熵,以便输出显示“图像的百分比”在某个特定的熵范围内。

my entropy code: (I'm using MATLAB 2015b)我的熵代码:(我使用的是 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)]);

You can put your code in a for loop:您可以将代码放入 for 循环中:

files = dir('c:\data\*.jpg');  % Or whatever filter will pick your images
for k = 1 : length(files)
   im = fullfile(files(k).folder, files(k).name)
   im = imread(im);
  
   % Your code %
   % but change Er = ... in Er(k) = ... and Eb(k) = ... 
   % so you can store the results
end

percentage = sum(Er > Eb) / numel(Er) * 100; % Percentage of images with red entropy higher than blue entropy

disp(['Percentage of images with red entropy higher than blue entropy: ' num2str(percentage)])

Be careful because if you post your code as it is, it will try to open 800 figures!!请小心,因为如果您按原样发布代码,它会尝试打开 800 个数字!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM