从文件夹中取出多张图片并在MATLAB中进行具体操作
Taking multiple images from a folder and perform specific operation in MATLAB
我知道如何计算单个图像通道的熵。但我想计算数据集中每个图像的熵(几乎 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)])
小心,因为如果您 post 按原样使用代码,它会尝试打开 800 个数字!
我知道如何计算单个图像通道的熵。但我想计算数据集中每个图像的熵(几乎 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)])
小心,因为如果您 post 按原样使用代码,它会尝试打开 800 个数字!