# InverseWaveletTransform of a list of rules

I want to extract coefficient images from a DiscreteWaveletTransform and replace them by modified images of the same dimensions.

However, when I use DiscreteWaveletData without specifying the input image dimensions the dimension of the InverseWaveletTransform result is halved, and when I explicitly specify the type of wavelet (HaarWavelet) and transform (DiscreteWaveletTransform) used in the original forward transform the result of InverseWaveletTransform has the right dimensions, but looks quite different from the original input image.

What am I doing wrong?

im = Import["ExampleData\lena.tif"];
dwd = DiscreteWaveletTransform[im, Automatic, 1];
inrules = dwd[All, {"Image"}];


{rec1, rec2, rec3} =
InverseWaveletTransform[#] & /@ {dwd, DiscreteWaveletData[inrules],
DiscreteWaveletData[inrules, HaarWavelet[], "DiscreteWaveletTransform"]}


ImageDimensions[#] & /@ {rec1, rec2, rec3}
{{150, 116}, {75, 58}, {150, 116}}

• I am searching for a solution to this problem, but can't you just use WaveletMapIndexed and try to work from there ? – Sektor Jun 21 '15 at 15:15

I believe the last problem is caused by the standard behavior of the "Image" option. By default, it seems that the resulting output images are color adjusted (for optimal visibility?).

inrules = dwd[All, {"Image"}]


Use "ImageFunction" -> Identity to prevent this:

inrules = dwd[All, {"Image", "ImageFunction" -> Identity}]


with an inverse transform of:

InverseWaveletTransform[
DiscreteWaveletData[inrules, HaarWavelet[],"DiscreteWaveletTransform"]
]


(see "Scope/Get coefficients" section of the DiscreteWaveletData documentation page)

As to your first problem, I can only guess. The specification DiscreteWaveletData[inrules] you used (with only the rules in place) is not listed as a possible syntax in the syntax box of the DiscreteWaveletData doc page, so one could say you're lucky you get any output at all. To construct a fully inverse-transformable object you're apparently supposed to use:

DiscreteWaveletData[Normal[dwd], dwd["Wavelet"], dwd["Transform"], dwd["DataDimensions"]]


(see "Properties & Relations" section of the DiscreteWaveletData documentation page).

• @lex BTW, welcome to Mathematica.StackExchange! – Sjoerd C. de Vries Jun 22 '15 at 5:42
• Thanks Sjoerd, you're right on both accounts! – Lex Toet Jun 22 '15 at 12:45

I might be wrong but I think there is nothing wrong with the current behavior. I think if you want to keep the size of the images you should keep the data. In order to do that you should use 'StationaryWaveletTransform' rather than 'DiscreteWaveletTransform'. So, below the code works...

im = Import["ExampleData\\lena.tif"];
swt = StationaryWaveletTransform[im, Automatic, 1]
inrules = swt [All, {"Image"}]


{rec1, rec2, rec3} =
InverseWaveletTransform[#] & /@ {swt, DiscreteWaveletData[inrules],
DiscreteWaveletData[inrules, HaarWavelet[],
"StationaryWaveletTransform"]}
ImageDimensions[#] & /@ {rec1, rec2, rec3}


{{150, 116}, {150, 116}, {150, 116}}