Haar wavelet denoising

Last Updated on September 13, 2013 by nghiaho12

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
  5. Remove the padding

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.noise_0

noise_15

noise_100

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.

Download

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

  1. 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. 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.

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

    1. 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.

Leave a Reply to rinku bathani Cancel reply

Your email address will not be published. Required fields are marked *