微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在计算 800 多幅图像的颜色通道熵并显示百分比时,我如何解决“不存在的字段”错误在 MATLAB 中?

如何解决在计算 800 多幅图像的颜色通道熵并显示百分比时,我如何解决“不存在的字段”错误在 MATLAB 中?

我想扫描一个包含 800 张图像的文件夹来计算它们的 RGB 通道熵(每个颜色通道的熵)。然后计算我的图像中有多少百分比的图像具有比蓝色通道更高的红色通道熵。我在下面添加了整个代码,当我运行它时,它显示一个错误

Reference to non-existent field 'folder'.

Error in Untitled (line 3)
   im = fullfile(files(k).folder,files(k).name);

我目前使用的是 MATLAB 2015b 版本。

files = dir('F:\images\*.png');  % Or whatever filter will pick your images
for k = 1 : length(files)
   im = fullfile(files(k).folder,files(k).name);
   im = imread(im);
   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);

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

我还上传folder,它现在只包含 5 张 PNG 图片,而不是 800 多张图片

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。