信息论实验报告
实验一 信息熵与图像熵计算
一、实验目的
1.复习MATLAB 的基本命令,熟悉MATLAB 下的基本函数。
2.复习信息熵基本定义, 能够自学图像熵定义和基本概念。
二、实验仪器、设备
1.计算机-系统最低配置 256M 内存、P4 CPU。
2.Matlab 仿真软件 - 7.0 / 7.1 / 2006a 等版本Matlab 软件。
三、实验内容与原理 (1)内容:
1.能够写出MATLAB 源代码,求信源的信息熵。
2.根据图像熵基本知识,综合设计出MATLAB 程序,求出给定图像的图像熵。 (2)原理
1. MATLAB 中数据类型、矩阵运算、图像文件输入与输出知识复习。
2. 利用信息论中信息熵概念,求出任意一个离散信源的熵(平均自信息量)。 自信息是一个随机变量,它是指某一信源发出某一消息所含有的信息量。所发出 的消息不同,它们所含有的信息量也就不同。任何一个消息的自信息量都代表不了 信源所包含的平均自信息量。不能作为整个信源的信息测度,因此定义自信息量的
数学期望为信源的平均自信息量:
信息熵的意义:信源的信息熵H是从整个信源的统计特性来考虑的。它是从平均意 义上来表征信源的总体特性的。对于某特定的信源,其信息熵只有一个。不同的信 源因统计特性不同,其熵也不同。
3.学习图像熵基本概念,能够求出图像一维熵和二维熵。
图像熵是一种特征的统计形式,它反映了图像中平均信息量的多少。图像的一 维熵表示图像中灰度分布的聚集特征所包含的信息量,令P
i 表示图像中灰度值为i的像素所占的比例,则定义灰度图像的一元灰度熵为:
Hpilogpi
i0255图像的一维熵可以表示图像灰度分布的聚集特征,却不能反映图像灰度分布的空间 特征,为了表征这种空间特征,可以在一维熵的基础上引入能够反映灰度分布空间 特征的特征量来组成图像的二维熵。选择图像的邻域灰度均值作为灰度分布的空间 特征量,与图像的像素灰度组成特征二元组,记为( i, j ),其中i 表示像素的灰度值 (0 <= i <= 255),j 表示邻域灰度(0 <= j <= 255),
2Pijf(i,j)/N
上式能反应某像素位置上的灰度值与其周围像素灰度分布的综合特征,其中f(i, j)
为特征二元组(i, j)出现的频数,N 为图像的尺度,定义离散的图像二维熵为:
Hpijlogpiji0255
构造的图像二维熵可以在图像所包含信息量的前提下,突出反映图像中像素位置的 灰度信息和像素邻域内灰度分布的综合特征.
- 1 -
信息论实验报告
四、实验步骤
1.求解信息熵过程:
1) 输入一个离散信源,并检查该信源是否是完备集。 2) 去除信源中符号分布概率为零的元素。 3) 根据平均信息量公式,求出离散信源的熵。 2.图像熵计算过程:
1) 输入一幅图像,并将其转换成灰度图像。 2) 统计出图像中每个灰度阶象素概率。
3) 统计出图像中相邻两象素的灰度阶联合分布矩阵。 4) 根据图像熵和二阶熵公式,计算出一幅图像的熵。
五.实验数据及结果分析 程序如下:
Information Theory experiment testing file *************.cn,22/08/2007testing Discrete Shannon Entropy discrete probabilities set
probSet = [ 0.1 0.2 0.3 0.15 0.25]; call CalEntropy function H = CalEntropy(probSet);
sprintf('Shannon Entropy is: %d',H) calculate the Image entropy
[H1,H2] = ImgEntropy('lena.jpg');
结果如下:
ans =
Shannon Entropy is: 2.228213e+000 ans =
1 ord image entropy is : 7.450501e+000 ans =
- 2 -
信息论实验报告
2 ord image entropy is : 6.158439e+000 六、思考题
举例说明图像熵、信息熵在现实中有何实践指导意义?
附1:信息熵计算源代码函数源程序 CalEntropy.m
Information Shannon Entropy calculation *************.cn,22/08/2007
- 3 -
信息论实验报告
array : Discrete Probabilities Set H : Output Shannon Entropy function H = CalEntropy(array) Vector number
num = length(array);
Check probabilities sum to 1: if abs(sum(array) - 1) > .00001, error('Probablities don''t sum to 1.') end
Remove any zero probabilities %% zeroProbs = find(array < eps); if ~isempty(zeroProbs), array(zeroProbs) = [];
disp('Removed zero or negative probabilities.') End
Compute the entropy
H = -sum(array .* log2(array)); % 单位 bit/symbol
附2:图像熵计算源代码
函数源程序 ImgEntropy.m
Image Entropy calculation %%%%%%%% *************.cn,22/08/2007img : input image data
H1,H2 : Output 1&2 order entropy function [H1,H2] = ImgEntropy(img) color image transformation I = imread(img); img = rgb2gray(I);
imview(I), imview(img); [ix,iy] = size(img);
compute probs for each scale level in image P1 = imhist(img)/(ix*iy); temp = double(img);
for the index of image piexl temp = [temp , temp(:,1)];
correlation prob matrix between [ 0 ... 255] gray levels
CoefficientMat = zeros(256,256); for x = 1:ix for y = 1:iy
i = temp(x,y); j = temp(x,y+1); CoefficientMat(i+1,j+1) = CoefficientMat(i+1,j+1)+1; end end
compute the prob of matrix P2 = CoefficientMat./(ix*iy); H1 = 0; H2 = 0; for i = 1:256
calculate 1 ord image entropy if P1(i) ~= 0
H1 = H1 - P1(i)*log2(P1(i)); end
compute 2 ord image entropy for j = 1:256 if P2(i,j) ~= 0
H2 = H2 - P2(i,j)*log2(P2(i,j)); end end end
H2 = H2/2; % mean entropy /symbol sprintf('1 ord image entropy is : %d',H1) sprintf('2 ord image entropy is : %d',H2) 函数调用实例 test.m
Information Theory experiment testing file *************.cn,22/08/2007testing Discrete Shannon Entropy discrete probabilities set
probSet = [ 0.1 0.2 0.3 0.15 0.25]; call CalEntropy function H = CalEntropy(probSet);
sprintf('Shannon Entropy is: %d',H) calculate the Image entropy
[H1,H2] = ImgEntropy('lena.jpg');
- 4 -