我知道如何计算单个图像通道的熵。但我想计算来自数据集(几乎800(的每个图像的熵;图像的"百分比"是多少;在某个特定的熵范围内。
我的熵代码:(我使用的是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)]);
您可以将代码放入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)])
要小心,因为如果你照原样发布代码,它会试图打开800位数!!