【问题标题】:How can I calculate Entropy of picture in two directions(Horizental and vertical)?如何计算两个方向(水平和垂直)的图片熵?
【发布时间】:2021-02-08 23:51:57
【问题描述】:

我需要在两个方向(水平和垂直)计算图片的熵? 如何在matlab上实现?

【问题讨论】:

  • 你能举一个例子来说明水平和垂直熵的含义吗?我习惯于计算整个图像的熵。
  • 除此之外,输入图像应该是灰度图像还是 rgb/彩色图像?
  • @MichaelTr7 你好,我的图像是灰度的。我在使用 2 个方向的熵作为特征的论文上读到它。
  • @MichaelTr7 这是那篇文章的doi:doi.org/10.1016/j.anres.2017.12.002
  • 从我的简短浏览看来,本文中只有一个熵方程,即方程 (5)。

标签: image matlab image-processing entropy


【解决方案1】:

待编辑:一些可能有用的信息。

使用 GLCM(灰度共现矩阵)查找图像的水平和垂直能量

基于评论中发布的与纹理分析相关的文档。要找到图像的水平和垂直能量,可以从 GLCM(灰度共现矩阵)中提取统计信息,特别是在本例中为 Energy 属性。要检查关系的最近邻居/值的方向。由于我使用这些函数的知识/经验有限,我建议您更深入地研究这些函数的所有属性。

方向/偏移量是一个向量,定义为: [Vertical_Direction Horizo​​ntal_Direction]

有用的相关 MATLAB 文档:

MATLAB Documentation: Create gray-level co-occurrence matrix from image

MATLAB Documentation: Texture Analysis Using the Gray-Level Co-Occurrence Matrix (GLCM)

脚本:

%Creating the sample image and plotting%
Sample_Image = imread("Greyscale_Image.png");

%Calculating the Gray-Level Co-Occurence Matrices%
Horizontal_Offset = [0 1];
Vertical_Offset = [1 0];

Horizontal_GLCM = graycomatrix(Sample_Image, 'offset', Horizontal_Offset, 'Symmetric', true);
Vertical_GLCM = graycomatrix(Sample_Image, 'offset', Vertical_Offset, 'Symmetric', true);

Horizontal_Statistics = graycoprops(Horizontal_GLCM);
Horizontal_Statistics.Energy

Vertical_Statistics = graycoprops(Vertical_GLCM);
Vertical_Statistics.Energy

有趣的是Horizontal_GLCMVertical_GLCM 的熵是相等的

entropy(Horizontal_GLCM)
entropy(Vertical_GLCM)


查找图像的熵(灰度/灰度)

前言:

图像和字符串的熵通常以下列形式定义:

其中,pi 是给定像素强度 I 的熵概率,H(s) 是信号/图像的熵。概率是像素强度/像素数的频率。这方面的一个例子可能包括:

像素数 = 8

像素强度:20 → 频率 = 1 → 概率 = 1/8 → 熵项 = -(1/8)×log2(1/8)
像素强度:80 → 频率 = 3 → 概率 = 3/8 → 熵项 = -(3/8)×log2(3/8)
像素强度:120 → 频率 = 3 → 概率 = 3/8 → 熵项 = -(3/8)×log2(3/8)
像素强度:160→频率=1→概率=1/8→熵项=-(1/8)×log2(1/8)

图像熵:

H(s) = [-(1/8)×log2(1/8)] + [-(3/8)×log2(3/8)] + [-(3/8)×log2( 3/8)] + [-(1/8)×log2(1/8)]

H(s) ≈ 1.811278(基于源编码对图像进行编码需要 2 位)

脚本:

方法一:使用entropy()函数

entropy() 函数返回图像的熵并设置对图像进行编码所需的位数的下限。更具体地说是Number_Of_Bits_Required = ceil(entropy(image))

%Creating the sample image and plotting%
Sample_Image = uint8([20 80 80 80; 120 120 120 160]);
imshow(Sample_Image,'InitialMagnification',1500);
title("Test Image");
set(gcf, 'Position',  [100, 100, 500, 400]);
axis on
xlabel('X-Axis'); ylabel('Y-Axis');

Image_Entropy = entropy(Sample_Image);

方法 2:使用循环计算

使用循环遍历所有独特的像素强度。通过使用条件设置的逻辑矩阵并获取该矩阵的总和来计算出现次数。然后通过将出现除以像素数来找到概率。然后将概率的log2() 添加到变量Calculated_Entropy 中,该变量将累加/累加与每个特定概率对应的所有熵项。

%Creating the sample image and plotting%
Sample_Image = uint8([20 80 80 80; 120 120 120 160]);
imshow(Sample_Image,'InitialMagnification',1500);
title("Test Image");
set(gcf, 'Position',  [100, 100, 500, 400]);
axis on
xlabel('X-Axis'); ylabel('Y-Axis');

%Finding the image dimensions%
[Image_Height,Image_Width] = size(Sample_Image);
Number_Of_Pixels = Image_Height*Image_Width;

%Evaluating the unique intensity values%
Unique_Intensities = unique(Sample_Image);

%Initializing variables for later use%
Number_Of_Unique_Intensities = length(Unique_Intensities);
Probabilities = zeros(Number_Of_Unique_Intensities,1);
Calculated_Entropy = 0;

%Scanning through the unique intensities and evaluating the probabilities%
for Intensity_Index = 1: Number_Of_Unique_Intensities

    %Grabbing a unique intensity value%
    Intensity_Value = Unique_Intensities(Intensity_Index,1);  
    
        %Evaluating the frequency of the unique intensity value%
        Check_Array = (Sample_Image == Intensity_Value);
        Probabilities(Intensity_Index,1) = sum(Check_Array,'all')/Number_Of_Pixels;
        Calculated_Entropy = -Probabilities(Intensity_Index,1)*log2(Probabilities(Intensity_Index,1))+Calculated_Entropy;
        
end

Image_Entropy = entropy(Sample_Image);

fprintf("Calculated entropy: %f\n",Calculated_Entropy);
fprintf("Using the entropy function: %f\n",Image_Entropy);

使用 MATLAB R2019b 运行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多