Sign in to follow this  
stroma

edge detection

Recommended Posts

darookie    1441
Try running a convolution filter.


(Each filter is a simple 3x3 matrix)

Find vertical edges:
|-1 0 1|
|-1 0 1|
|-1 0 1|

Find horizontal edges:
|-1 -1 -1|
| 0 0 0|
| 1 1 1|

Find both edges (yeah, it's not correct [wink]):
| 1 0 -1|
| 0 0 0|
|-1 0 1|

Sobel operator:
|-1 0 1|
|-2 0 2|
|-1 0 1|

|-1 -2 -1|
| 0 0 0|
| 1 2 1|

There are more advanced methods, too. But these should give you a good start.

Have fun,
Pat.

Share this post


Link to post
Share on other sites
stroma    218
i always use google and others... before posting but i wanted to be sure about useful ones. [wink]
thanks for document but i did not understand anything about the matrices you wrote [headshake] are they usefull for non-convex shapes? what is "convolution filter"?

Share this post


Link to post
Share on other sites
darookie    1441
Images can be filtered using such matrices. Basically you loop over the pixel values and depeding on the size of the convolution kernel (such as the matrices I wrote) combine neighboring with it using the values stores in the filter.

Each value in the filter is a factor that the corresponding neighbouring pixel value is multiplied with. The values are all summed up and the result is written back to the original pixel position.
Sounds complicated, but it really isn't. If I had Tex support on this bord, I'd write down the formula (but I guess it would only confuse you).

Example:


Below are sample pixel values:
ABCDEF
GHIJKL
MNOPQR
STUVWX

The filter is [-1 0 1] (one dimensional for simplicity).

So to get the filtered value of pixel 'B', you apply the filter like so:

B* = A * (-1) + B * 0 + C * 1

So in essence if you have a n x m filter matrix, you apply the filter to each pixel (x,y):


// pseudo code: do this for each pixel in the image
void FilterPixel(int x, int y) {
int filteredPixel = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
filteredPixel += image[x - n/2 + i ,y - m/2 + j] * filterKernel[i, j];
}
}
// optionally you can clamp the final pixel value or use a threshold or take the absolute value of it.
image[x,y] = filteredPixel;
}



As you might see filter kernels should have odd sizes (f.e. 3x3, 5x5, 7x7 but not 4x4). There are problems at the image boundaries, where the filter cannot be applied correctly (e.g. 'x - n/2' will not work for x == 0). In this case there are a few options:


  • Plug in a constant for the missing values (e.g. '0' for simplicity[wink])

  • Extend the image periodially (i.e. repeat the last values)

  • Mirror at the boundaries mirror the available pixel values at the pixel center (in the above example filtering pixel 'A' by [-1 0 1] results in filtering 'BAB' o [-1 0 1])

  • Repeat the last available data as often as necessary (in the above example this would result in 'AAB' o [-1 0 1])



Here's a more formal description (along with the formulas): Clicky.

Good luck!
Pat.

Share this post


Link to post
Share on other sites
Extrarius    1412
There are definitely some VERY good algorithms out there for edge detection. I can't remeber the name of the book, but I've seen an example in a digital imaging processing book that showed how both edge detection and line extension could be used to extract the license plate numbers off a blurry picture of a van (it also correctly extract the bounds of the windows, the seam on the split back door and the general shape of the vehicle and bumper =-)

Definitely some amazing algorithms out there

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this