graetz23/JWave

Different with Matlab?

DionK90 opened this issue · 3 comments

Dear Christian,

I am trying to use this library, and it gives me results. Basically, this is what my code do:

  1. load an image (I use the "woman" image in matlab).
  2. get the pixel values
  3. call forward method (FWT with Haar / Sym8)
    transform.forward(pixels, 1, 1) //apparently, dwt2 in Matlab only apply 1 level FWT)
  4. normalized the result to 0-255
  5. print the image

However, I also tried to use dwt in Matlab and it gives me a different result, most notably are:

  1. For each additional vanishing moment N, the result has more dimension (image size + N - 1)
  2. Image attached for both result in Matlab and Java
    matlabhaar
    normhaar
    matlabsym8
    normsym8

Additionally, I try to compare both library with 4x4 all-ones matrix using Haar Wavelet (again by calling forward(matrix, 1, 1)). The coefficients are basically the same with different signs in upper right and lower left elements.
Here is an example of the result:
-Matlab (I crop it to 4x4 from 18x18)
2 2 -2.97996696763114e-12 -2.97996696763114e-12
2 2 -2.97996696763114e-12 -2.97996696763114e-12
-2.97995268873730e-12 -2.97995268873730e-12 4.44003260755500e-24 4.44003260755500e-24
-2.97995268873730e-12 -2.97995268873730e-12 4.44003260755500e-24 4.44003260755500e-24

-Java
2.0 2.0 2.9799526887373042E-12 2.9799526887373042E-12
2.0 2.0 2.9799526887373042E-12 2.9799526887373042E-12
2.9799669676311424E-12 2.9799669676311424E-12 4.440032607554995E-24 4.440032607554995E-24
2.9799669676311424E-12 2.9799669676311424E-12 4.440032607554995E-24 4.440032607554995E-24

What exactly is happening here? Is there something I do wrong?

Sorry, I forgot to mention that printing the image is done by treating the normalized wavelet coefficient as pixel values.

Hi DionK90,

sorry for being late in answer but I am very busy those days.

Thanks for your input, great job!
I did the same around 7 years ago with images in C++ code instead java and MATLAB.

I have two answers for you:

First, If you have a precsion betweenn a 2.E-0 and a 2.9799526887373042E-12, the E-12 can be seen as "numerical zero", independently of the sign.

Second, by wavelets theory you have the possiblity to implement the transform algorithms in several ways, due to having an orthogonal (orthonormal) basis, the wavelets. My implementation adds up each level (step) to the coefficients (low pass, engery & high pass, details) before, and splits it up again in the reverse transform. This allows for not having larger matrices while transforming and, therfore, opens the way to a very efficient image compression.

My fwt works for the Haar like:

signal: low0_1, low0_2, low0_3, low0_4, low0_5, low0_6, low0_7, low0_8
haar_fwt1: low1_1, low1_2, low1_3, low1_4, high1_1, high1_2, high1_3, high1_4
haar_fwt2: low2_1, low2_2, high2_1, high2_1, high1_1, high1_2, high1_3, high1_4
haar_fwt3: low3_1, high3_1, high2_1, high2_1, high1_1, high1_2, high1_3, high1_4
(8=2^3 => 3 steps useful)

As a note, independent of how the transform algorithm is implemented, displaying information using any orthogonal wavelet basis is the big gain.

best
Christian

Hey Guys!
Could you give me a code example of how to do a fastWaveletTransform, forward or reverse, in an image java from reading to the writing.
I would appreciate a lot, thanks!!!