1
$\begingroup$

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"}];

enter image description here

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

enter image description here

ImageDimensions[#] & /@ {rec1, rec2, rec3}
{{150, 116}, {75, 58}, {150, 116}}
$\endgroup$
  • $\begingroup$ I am searching for a solution to this problem, but can't you just use WaveletMapIndexed and try to work from there ? $\endgroup$ – Sektor Jun 21 '15 at 15:15
1
$\begingroup$

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"}]

Mathematica graphics

Use "ImageFunction" -> Identity to prevent this:

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

Mathematica graphics

with an inverse transform of:

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

enter image description here

(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).

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

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"}]

enter image description here

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

enter image description here

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.