Discrete Wavelets with Applications

033 - Qualitatitive and Quantitative Measures

Helmut  Knaust - Department of Mathematical Sciences, University of Texas at El Paso, hknaust@utep.edu
09/15/2010. Last edits 9/16/2020.

SetDirectory[NotebookDirectory[]];<<DW.wl
SetDirectory["Images"]

Entropy

The entropy of a vector (or matrix) gives you the theoretical lower bound for the binary storage requirement in bits per pixel (bpp).

data=RandomInteger[{0,15},25]

' ShannonEntropy' is a command in the 'DW.m' package :

ShannonEntropy[data]

Let' s look at some extreme cases :

ShannonEntropy[{1,2,3,4,5,6,7,8}]

ShannonEntropy[{1,1,1,1,1,1,1,1}]

ShannonEntropy[{1,2,3,4}]

ShannonEntropy[RandomInteger[{0,255},50000]]

SetDirectory["Grayscale"];file="tower_small.png";pic=Import[file,"Data"];
ImagePlot[pic]

ShannonEntropy[pic]

Let' s compare the entropies for the the channels of the RGB and YCbCr color space representations of an image :

SetDirectory["..\\Color"];pic=Import["building_small.png","Data"];{dimr,dimc}=Dimensions[pic][[1;;2]];
fct=({16+1/256(65.738#[[1]]+129.057#[[2]]+25.064#[[3]]),128+1/256(-37.945#[[1]]-74.494#[[2]]+112.439#[[3]]),128+1/256(112.439#[[1]]-94.154#[[2]]-18.285#[[3]])}&);
YCbCr=Round[Map[fct,pic,{2}]];

The second row depicts the RGB channels, the last row shows the YCbCr channels. Entropies are listed below the respective images.

Grid[{{ImagePlot[pic]},{ImagePlot[pic[[All,All,1]]],ImagePlot[pic[[All,All,2]]],ImagePlot[pic[[All,All,3]]]},{ShannonEntropy[pic[[All,All,1]]],ShannonEntropy[pic[[All,All,2]]],ShannonEntropy[pic[[All,All,3]]]},{ImagePlot[YCbCr[[All,All,1]]],ImagePlot[YCbCr[[All,All,2]]],ImagePlot[YCbCr[[All,All,3]]]},{ShannonEntropy[YCbCr[[All,All,1]]],ShannonEntropy[YCbCr[[All,All,2]]],ShannonEntropy[YCbCr[[All,All,3]]]}}]

Best possible total bit size for the RGB and YCbCr color space representations and "savings" by using YCbCr :

pixels=dimr dimc;Print["RGB color space:       ",rgb=Ceiling[Total[pixels{ShannonEntropy[pic[[All,All,1]]],ShannonEntropy[pic[[All,All,2]]],ShannonEntropy[pic[[All,All,3]]]}]]," bits"]
Print["YCbCr color space:   ",ycc=Ceiling[Total[pixels{ShannonEntropy[YCbCr[[All,All,1]]],ShannonEntropy[YCbCr[[All,All,2]]],ShannonEntropy[YCbCr[[All,All,3]]]}]]," bits"]
Print["Savings ≈ ",Floor[100 (rgb-ycc)/rgb],"%"]

Cumulative Energy

The energy of a vector is the sum of its squared components: Energy((Subscript[v, 1, ])(Subscript[v, 2]),...(Subscript[v, n  ])) = (Subscript[(∑^n), i=1]) ((Subscript[v, i])^2).

data={1,-2,3,-3,5,-5,6,-6,6}

data2=Reverse[Sort[Abs[data]]]

data3=data2^2/Norm[data2]^2

data4=Accumulate[data3]

ListPlot[data4,Joined->True,AxesOrigin->{0,0}]

Here is the ' DW.m " command:

CEnergy[data]

CEnergy[RandomInteger[{0,255},10000]]

SetDirectory["..\\Grayscale"];file="tower_small.png";pic=Import[file,"Data"];
ImagePlot[pic]
p1=CEnergy[pic]

Applying a γ - correction (this operation does not preserve energy!):

g2=Round[255(pic/255.)^5];
ImagePlot[g2]
p2=CEnergy[g2,PlotStyle->{Thick,Blue}]

Show[{p1,p2}]

Peak Signal to Noise Ratio

file="clown.png";pic=Import[file,"Data"];

A comparison of an image with one of its γ - corrections :

γ=1.1;Grid[{{ImagePlot[pic],gpic=Round[255(pic/255.)^γ];ImagePlot[gpic]}}]

PSNR[pic,gpic]

ImagePlot[255-Abs[pic-gpic],Scaled->False]

Our Engineering Problem

How to transform a grayscale image to obtain small entropy and large PSNR when compared to the original image.