Click here to Skip to main content
Email Password   helpLost your password?
Screenshot - edges.jpg

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:

1 scale daub1 FWT

You will get this FWT spectrum:

FWT spectrum

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

Removed low freq 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:

In two steps to get edges

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:

The edges

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:

The more prominent 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.

The edges by Sobel filter

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.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralMy vote of 1
G.subburaju
19:15 21 Dec '09  
sdsds
GeneralDe-noising
CPPCoder
15:33 16 Apr '08  
I need to filter out noise in an image. How this denoising can be achieved using this library. By default FWT library take filter name and for denoising is there any specific filter which will suppress high frequency noises alone. If I do FWT2D RGB Transform (With no filter selected and threshold is 3), Denoise and FWT2D RGB Synth the reconstructed image is not denoised by lost considerable image data. It will be great if you could provide help on this.
Generalneed your help
gulsaba
7:41 31 Mar '08  
hylo sir
i want to detect edges of a projector screen who's image is captured by a camera.i will be very thankful if you provide me sum help
gul
Generalcompile problem
A.DEEPA
21:52 21 Mar '08  
Sir,

Please tell me how to compile your code in VC++ without .dsw files or if possible please give me a link to that file

deepa
AnswerRe: compile problem
Chesnokov Yuriy
4:45 25 Mar '08  
Sir,

But the GUI is a .NET project you need VS2005 to compile it. There are no .dsw files in it. The lib is pure C++ though.

chesnokov

GeneralCool
Dr.Luiji
5:47 19 Dec '07  
Very cool article Yuriy, I put it in my own bookmarks.
5 stars are deserved.

Dr.Luiji

Trust and you'll be trusted.


Generalserious drawback of this approach
hartwin
21:49 22 Nov '07  
There is a serious drawback of detecting edges with the wavelet transformation(WT):

It depends on the level (0...255) of the edge if it is detected or not.

Assume there is noise in the image with an amplitude of 3 and assume further that there is only a single edge in the image with an amplitude of 6 ranging from 125 to 111. This is the edge is at level 128. The WT will cut it into two peaces:
125 to 127
and 128 to 111.
Thus destroying the edge and separating it into two peaces that just integrate into the noisy background. After filtering out the the first spatial freqency and reconstructing the image will provide a noisy image with no edge at all.

Now assume the edge is at a level of 100. Now one can filter out the first spatial frequency, reconstruct the image and even subdue the noise providing a hommogenouse image with the edge, that can be perfectly detected by a threshold operation.

The bad message of this is: The level of 128 is not the only probleme. Level of 64 and 196 cause problems with filtering out the second spatial freqency and so on. And further on: The higher the noise the worser it gets with the detection of edges.

And that is why the wavelet edge filter produce disgusting edge images in comparision to sobel filtered images.

The wavelet haar transformation will not give robust results in edge detection. Therefore improve the approach or forget it.


hartwin

AnswerRe: serious drawback of this approach - serious drawback with your question :-)
Chesnokov Yuriy
23:48 22 Nov '07  
Thank you for your thorough comments. But it provides! have a look at the pictures! You can not deny obvious.

It is not so bad nowadays. Even web cams about 20$ produce nice images without high noise you pointed.

This is not the article comparing artificially created noisy pictures and geting the algorithms to get the edges from barely visible edges to post them into peer journals.

There are beamlets that outperform sobel for the topic you pointed geting edges from high noisy pics of galaxies and the like, have a look at the papers. I probably will write the beamlets code and post it comparing with sobel.

This article about speed improvement on normal data, from not spoiled web cams producing normal data, comparing to sobel, and not high noisy pictures Smile forget about it.


chesnokov

RantRe: serious drawback of this approach
Pythorian
21:37 2 Dec '08  
I realize I am a year late, but I felt compelled to point this out. You seem really stupid when you cannot spell properly. I am completely shocked at the author's gracious response to your waste of his time.
General.jpg image is missing from .zip
elwolv
3:51 20 Nov '07  
hello

.jpg image is missing from .zip

elwolv

elwolv

GeneralRe: .jpg image is missing from .zip
Chesnokov Yuriy
21:05 20 Nov '07  
I did not include it. The jpeg is available is Windows Vista's images

chesnokov


Last Updated 14 Nov 2007 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010