12,404,895 members (71,121 online)
alternative version

113.3K views
146 bookmarked
Posted

# Edge Detection in Images with Wavelet Transform

, 14 Nov 2007 GPL3
 Rate this:
This article demonstrates an alternative way for edges extraction compared to conventional image filtering operations with edge detection filters

## Introduction

Edge detection is used in computer vision applications for contours extraction of objects. The usual method is to use convolution operation of the image with complex filters like Sobel or Prewitt.

### Sobel Filter

```Real
1.0  0.0 -1.0
2.0  0.0 -2.0
1.0  0.0 -1.0
Imaginary
1.0  2.0  1.0
0.0  0.0  0.0
-1.0 -2.0 -1.0```

### Prewitt Filter

```Real
0.5  0.0 -0.5
0.5  0.0 -0.5
0.5  0.0 -0.5
Imaginary
0.5  0.5  0.5
0.0  0.0  0.0
-0.5 -0.5 -0.5```

You may extract the edges for example with my `vec2D` wrapper described in my article Vector Class Wrapper SSE Optimized for Math Operations.

However unless integer optimized, floating point operations might take quite a long time. With wavelet transform, you might achieve similar results with a few mathematical operations. For example, Haar transform of the image provides details of that image contained in the high frequency bands very similar in appearance if you used X and Y difference filters on the same image.

### X Difference Filter

```0.0  0.0  0.0
0.5  0.0 -0.5
0.0  0.0  0.0```

### Y Difference Filter

```0.0  0.5  0.0
0.0  0.0  0.0
0.0 -0.5  0.0```

If we keep the details of the image obtained with Haar transform, remove the coarse-grained low frequency component and perform image reconstruction, we obtain the edges of the objects present in the image.

## Background

Image processing background for Edge Detection is needed. You might also consult my articles about wavelet analysis of image data: 2D Fast Wavelet Transform Library for Image Processing and Fast Dyadic Image Scaling with Haar Transform.

## Using the Code

The code and the demo application are used from my article 2D Fast Wavelet Transform Library for Image Processing where you may find details on how to run the code and use the library. In this project, I added several edge specific operations so you may experiment with different wavelet filters, scales, and denoising thresholds to select the best combination. Below I demonstrate the `daub1` filter application, which is the filter used in Haar transform.

Open the image and transform it to 1, 2 or 3 scales. You might add the threshold to remove the noise. Below, the `daub1` filter is selected with 1 scale transform without denoising:

You will get this FWT spectrum:

Now click Transform->Denoise menu item to remove low frequency component:

You might find the corresponding function in the `BaseFWT2D` class:

```void BaseFWT2D::remove_LLband()
{
if (m_status <= 0)
return;

unsigned int width = m_width /
(unsigned int)(pow(2.0f, (float)getJ()));
unsigned int height = m_height /
(unsigned int)(pow(2.0f, (float)getJ()));

for (unsigned int y = 0; y < height; y++)
for (unsigned int x = 0; x < width; x++)
spec2d[y][x] = 0;
}```

Now you may reconstruct the image:

It does not seem like the edges yet. You need just subtract 128 from the image and compute the absolute value with Transform->Abs values menu item:

But the edges are rather vague. First I proceeded with contrast stretching, that is normalizing the image to 0 ... 255 range. But there might be several pixels at the upper limit of the range and it does not really improve the situation. The better choice would be non-linear normalization like logarithmic scale but I just multiply the pixel data by some value and obtain the more prominent edges. For 1 scale transform, the multiplication by 7 works well and does not overflow the 255 limit for the majority of pixels, but for 2 or 3 scales you might diminish the multiplication number.

Now click Transform->Contrast stretch to amplify your edges:

You may compare the same picture results I obtained with the Sobel filter. It looks smoother, but then you might proceed to morphological operations like erosion and dilation and get a thin skeleton of the contour so in the end, the results will be very close.

I've developed Haar transform MMX optimization and in future, plan to provide an update to the code as `EdgeDetector` class or something similar and compare the performance.

## Share

 Engineer Russian Federation
Highly skilled Engineer with 14 years of experience in academia, R&D and commercial product development supporting full software life-cycle from idea to implementation and further support. During my academic career I was able to succeed in MIT Computers in Cardiology 2006 international challenge, as a R&D and SW engineer gain CodeProject MVP, find algorithmic solutions to quickly resolve tough customer problems to pass product requirements in tight deadlines. My key areas of expertise involve Object-Oriented
Analysis and Design OOAD, OOP, machine learning, natural language processing, face recognition, computer vision and image processing, wavelet analysis, digital signal processing in cardiology.

## You may also be interested in...

 First Prev Next
 My vote of 5 KakuOceam21-May-13 16:59 KakuOceam 21-May-13 16:59
 thanks tnla14-Jan-12 23:20 tnla 14-Jan-12 23:20
 My vote of 5 abcdezhao200817-Nov-11 2:21 abcdezhao2008 17-Nov-11 2:21
 Just comments Vaclav_Sal6-Nov-10 11:08 Vaclav_Sal 6-Nov-10 11:08
 Re: Just comments Chesnokov Yuriy7-Nov-10 8:14 Chesnokov Yuriy 7-Nov-10 8:14
 Question sergiodd24-Aug-10 2:46 sergiodd 24-Aug-10 2:46
 Re: Question Chesnokov Yuriy24-Aug-10 2:57 Chesnokov Yuriy 24-Aug-10 2:57
 Re: Question [modified] sergiodd24-Aug-10 3:12 sergiodd 24-Aug-10 3:12
 My vote of 1 G.subburaju21-Dec-09 18:15 G.subburaju 21-Dec-09 18:15
 De-noising CPPCoder16-Apr-08 14:33 CPPCoder 16-Apr-08 14:33
 need your help gulsaba31-Mar-08 6:41 gulsaba 31-Mar-08 6:41
 compile problem A.DEEPA21-Mar-08 20:52 A.DEEPA 21-Mar-08 20:52
 Re: compile problem Chesnokov Yuriy25-Mar-08 3:45 Chesnokov Yuriy 25-Mar-08 3:45
 Cool Dr.Luiji 19-Dec-07 4:47 Dr.Luiji 19-Dec-07 4:47
 serious drawback of this approach hartwin22-Nov-07 20:49 hartwin 22-Nov-07 20:49
 Re: serious drawback of this approach - serious drawback with your question :-) Chesnokov Yuriy22-Nov-07 22:48 Chesnokov Yuriy 22-Nov-07 22:48
 .jpg image is missing from .zip elwolv20-Nov-07 2:51 elwolv 20-Nov-07 2:51
 Re: .jpg image is missing from .zip Chesnokov Yuriy20-Nov-07 20:05 Chesnokov Yuriy 20-Nov-07 20:05
 Last Visit: 31-Dec-99 18:00     Last Update: 28-Jul-16 23:17 Refresh 1