| ntojzan 2004-06-25, 6:56 pm |
| "CAFxX" <caf@n-side.it> wrote in message news:<casgrj$od0$1@lacerta.tiscalinet.it>...
> every time i search on the web for haar's wavelet they say that the above
> algorithm should be enough, but as i always thought, it doesn't work.
> actually i can't figure out how to transform two char values getting in
> return just 8 + 8 bits and not 8 + 9.
> can anyone here explain me where's my mistake?
There is no mistake. However if you are using the wavelet to create a
lossy compression, you might consider this:
Haar Transformation:
c=a+b
d=a-b
Reversed Haar transformation:
a=(c+d)/2
b=(c-d)/2
Quantized (and messed up) Haar:
c=(a+b) shr 1
d=(256+a-b) shr 1
Reversed quantized Haar:
a=c+d-128
b=c-d+128
So, here you have a fixed quantization by factor 2, and the formulas
are much more easy to compute. However, you've already lost the least
significant bit from your calculations.
Offcourse if you'll have the ability to change the quantization
factor, then you dont even need this trick, for example I use a
temporary buffer of signed words for the calculation, and later divide
the result by a factor of 64 for the 4x4x4 transform. You can also
divide your results by any quantization factor as long as it is more
or equal than 2, and you'll have it stored in bytes. (if that is your
goal, isn't it?)
NOTE: I've added 256 to a-b in order to keep the result values as
unsigned bytes.
Re.
|