實習 一 影象熵的計算

2023-01-10 17:45:02 字數 3561 閱讀 9197

實驗一lena影象的一維熵與二維熵計算

實驗內容

1.能夠寫出matlab 源**,求lena影象的一維熵。

2.考慮像元空間相關性,求lena影象的二維熵。

實驗原理

1.matlab 中資料型別、矩陣運算、影象檔案輸入與輸出知識複習。

2.利用資訊理論中資訊熵概念,求出任意乙個離散信源的熵(平均自資訊量)。

任何乙個訊息的自資訊量都代表不了信源所包含的平均自資訊量。不能作為整個信源的資訊測度,因此定義自資訊量的數學期望為離散信源的平均自資訊量:

稱之為信源的資訊熵。h是從整個信源的統計特性來考慮的,它是從平均意義上來表徵信源的總體特性的。對於某特定的信源,其資訊熵只有乙個;不同的信源因統計特性不同,其熵也不同。

3.學習影象熵基本概念,能夠求出影象一維熵和二維熵。

影象熵反映了影象中平均每個像元含有資訊量的多少。一維熵將像元看作相互獨立,表示影象中灰度分布的聚集特徵。令pi 表示影象中灰度值為i的畫素所佔的比例,計算影象的一元灰度熵為:

影象的一維熵可以表示影象灰度分布的聚集特徵,卻不能反映影象灰度分布的空間特徵,為了表徵這種空間特徵,可以在一維熵的基礎上引入能夠反映灰度分布空間特徵的特徵量來組成影象的二維熵。選擇影象的鄰域灰度均值作為灰度分布的空間特徵量,與影象的畫素灰度組成特徵二元組,記為( i, j ),其中i表示畫素的灰度值,j 表示鄰域灰度,f(i, j)為特徵二元組(i, j)出現的頻數。計算聯合概率

其中mn等於影象的總像元數。定義離散的影象二維熵為:

構造的影象二維熵可以在影象所包含資訊量的前提下,突出反映影象中畫素位置的灰度資訊和畫素鄰域內灰度分布的綜合特徵. (原影象與均值平滑後的影象的聯合熵,再除以1/2.)

實驗步驟

1) 輸入一幅影象,並將其轉換成灰度影象。

2) 統計出影象中每個灰度階象素概率。

3) 統計出灰度階聯合分布矩陣。

4) 根據影象熵和二階熵公式,計算出一幅影象的熵。

五.實驗資料及結果分析

testing discrete shannon entropy

probset = [ 0.1 0.2 0.3 0.15 0.25]; %discrete probabilities set

h = calentropy(probsetcall calentropy function

sprintf('shannon entropy is: %d',h)

calculate the image entropy

[h1,h2] = imgentropy('');

ans =

shannon entropy is: 2.228213e+000

ans =

1 ord image entropy is : 7.450501e+000

ans =

2 ord image entropy is : 6.158439e+000

附1:資訊熵計算

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('probablitiesdon''t sum to 1.')

endremove any zero probabilities %%

zeroprobs = find(array if ~isempty(zeroprobs),

array(zeroprobs) = ;

disp('removed zero or negative probabilities.')

endcompute the entropy

h = -sum(array .* log2(array));

% 單位bit/symbol

附2:影象熵計算

img : 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);

computeprobs for each scale level in image

p1 = imhist(img)/(ix*iy);

temp = double(img);

for the index of image piexl

temp = [temp , temp(:,1)];

correlationprob 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;

endend

compute the prob of matrix

p2 = coefficientmat./(ix*iy);

h1 = 0; h2 = 0;

fori = 1:256

calculate 1 ord image entropy

if p1(i) ~= 0

h1 = h1 - p1(i)*log2(p1(i));

endcompute 2 ord image entropy

for j = 1:256

if p2(i,j) ~= 0

h2 = h2 - p2(i,j)*log2(p2(i,j));

endend

endh2 = h2/2; % mean entropy /symbol

sprintf('1 ord image entropy is : %d',h1)

sprintf('2 ord image entropy is : %d',h2)

函式呼叫例項

information theory experiment testing file

22/08/2007

testing discrete shannon entropy

discrete probabilities set

probset = [ 0.1 0.2 0.3 0.15 0.25];

callcalentropy function

h = calentropy(probset);

sprintf('shannon entropy is: %d',h)

calculate the image entropy

[h1,h2] = imgentropy('');

鋁的影象計算題

1.向30毫公升1 mol l的alcl3溶液中逐漸加入濃度為4 mol l的naoh溶液,若產生0.78克白色沉澱,則加入的naoh溶液的體積可能為 a.3ml b.7.5ml c.15ml d.27.5ml 2.向含有a mol alcl3的溶液中加入含b mol koh的溶液,生成沉澱的物質的...

函式的影象變換 一

1.函式的圖象是 abcd 2.當時,在同一座標系內,函式與的圖象是 abcd 3.為了得到函式的圖象,可以把的圖象 a 向左平移3個單位長度b 向右平移3個單位長度 c 向左平移1個單位長度d 向右平移1個單位長度。4.為了得到函式的圖象,可以把的圖象 a 向左平移個單位長度b 向右平移個單位長度...

一次函式的影象 2

課題 6.3一次函式的圖象 二 編號 43課型 新授課班級 姓名 教學重點 結合一次函式的圖象,一次函式的簡單性質.學習過程 一 課前複習 1 一次函式表示式的k b 2 直線經過點 1,02 0 3 在同一直角座標系下作出函式影象 4 不在一次函式圖象上的點是 a.2,3 b.2,1 c.0,3 ...