2D DWT detailed  "compression" example #2

Load gray-scale image

img = ReadImage["bakery256x256.ppm"] ; scale = 1 ;

Display image

ShowImage[img, scale] ;

[Graphics:../HTMLFiles/index_58.gif]

Define wavelet filter

db4 = DaubechiesFilter[4] ;

Compression example (Daubechies-4, 5-level)

DWT output size

imgsize = 500 ;

Define filter, levels, output options

filter = db4 ; level = 5 ; func = Abs ; plotstyle = PlotRangeAutomatic ;

DWT

dwt = WaveletTransform2D[img, filter, level] ; ShowWaveletTransform2D[dwt, level, func, plotstyle, ImageSizeimgsize] ;

[Graphics:../HTMLFiles/index_63.gif]

Eliminate progressively more small wavelet coefficients

CompressImage[dwt_, thresh_] := Map[If[Abs[#] < thresh, 0, #] &, dwt, {2}] ;

dwtc = CompressImage[dwt, #] & /@ {1, 5, 10, 25, 50, 75, 100, 150} ;

Count number of nonzero wavelet coefficients as threshold is increased

(100 ((Times @@ Dimensions[img]) - (Position[#, 0] // Length))/(Times @@ Dimensions[img])) & /@ dwtc // N

RowBox[{{, RowBox[{82.2433, ,, 45.5673, ,, 29.686, ,, 12.3917, ,, 4.67987, ,, 2.66266, ,, 1.85242, ,, 1.11237}], }}]

Show compressed DWTs

ShowWaveletTransform2D[#, level, func, plotstyle, ImageSizeimgsize] & /@ dwtc ;

[Graphics:../HTMLFiles/index_69.gif]

[Graphics:../HTMLFiles/index_70.gif]

[Graphics:../HTMLFiles/index_71.gif]

[Graphics:../HTMLFiles/index_72.gif]

[Graphics:../HTMLFiles/index_73.gif]

[Graphics:../HTMLFiles/index_74.gif]

[Graphics:../HTMLFiles/index_75.gif]

[Graphics:../HTMLFiles/index_76.gif]

Take inverse DWTs

imgc = InverseWaveletTransform2D[#, filter, level] & /@ dwtc ;

Show compressed images

ShowImage[#, scale] & /@ imgc ;

[Graphics:../HTMLFiles/index_79.gif]

[Graphics:../HTMLFiles/index_80.gif]

[Graphics:../HTMLFiles/index_81.gif]

[Graphics:../HTMLFiles/index_82.gif]

[Graphics:../HTMLFiles/index_83.gif]

[Graphics:../HTMLFiles/index_84.gif]

[Graphics:../HTMLFiles/index_85.gif]

[Graphics:../HTMLFiles/index_86.gif]


Created by Mathematica  (February 16, 2004)