# Haar wavelet denoising

This is some old Haar wavelet code I dug up from my PhD days that I’ve adapted to image denoising. It denoises an image by performing the following steps

1. Pad the width/height so the dimensions are a power of two. Padded with 0.
2. Do 2D Haar wavelet transform
3. Shrink all the coefficients using the soft thresholding: x = sign(x) * max(0, abs(x) – threshold)
4. Inverse 2D Haar wavelet transform

I’ve coded a simple GUI using OpenCV to show the denoising in action. There’s a slider that goes from 0 to 100, which translates to a threshold range of [0, 0.1].

I’ll use the same image in a previous post. This is a cropped image taken at night on a point and shoot camera. The noise is real and not artificially added.

The Haar wavelet does a pretty good job of preserving edges and sharp transitions in general. At threshold = 100 you start to see the blocky nature of the Haar wavelet.

One downside of using the Haar wavelet is that the image dimensions have to be a power of two, which wastes memory and CPU cycles when we have to pad the image.

haar_wavelet_denoising.cpp

Compile using GCC with

`g++ haar_wavelet_denoising.cpp -o haar_wavelet_denoising -O3 -lopencv_core -lopencv_highgui -lopencv_imgproc`

and run via

`./haar_wavelet_denoising image.jpg`

## 7 thoughts on “Haar wavelet denoising”

1. Drazick says:

From you experience,
What would be the best Denoising algorithm for real world photos (Taken with Digital Camera)?

1. nghiaho12 says:

I honestly haven’t put too much time looking into this. Nearly all of the noise I observe in digital photos are mostly low light noise (high ISO). From what I observed they tend to follow a Gaussian quite closely. Any denoising algorithm targeting Gaussian would be a good start. The best I’ve seen so far are probably algorithms based on sparse coding/compressed sensing.

2. Vineet says:

Your PCA stuff really helped. I’m working on video content retrieval now. Any innovative tips to streamline the matching or the retrieval process other than hash buckets?

1. nghiaho12 says:

Are using PCA or Haar wavelet? I’ve found doing brute forcing on a small handful of coefficients to be really fast in the past. You can easily match a few 100,000 scene signatures easily these days. I’ve never found the need to do hashing, so won’t be of any help there.

3. rinku bathani says:

which algorithms are used for noise identification and noise remove for real world photos (Taken with Digital Camera) in opencv??

1. nghiaho12 says:

Don’t know actually, never did reserch on this topic. I just did this demo because I had some experience with Haar wavelets, not so much denoising.

1. rinku bathani says:

kkzz..thanks..