Iam doing my final year project on license plate regonsition and
needed some help on
sobel edge detection code in c++ to apply on a license plate.
Is there any one that can provide me with the sobel code.
Just look for a library that provides a 3x3 kernel operator, then feed
it the Sobel kernel. This link might be useful:
http://www.codeproject.com/bitmap/ImageConvolution.asp
--
Mike Smith
If I recall well the horizontal and vertical sobel operators are
1 |1 0 -1|
-- |2 0 -2|
8 |1 0 -1|
1 |1 2 1|
-- |0 0 0|
8 |-1 -2 -1|
eg in the first (horizontal) case if you want to compute the edge of the
current pixel you multiply the NW pixel by 1, NE by -1, W by 2, E by -2, SW
by 1 and SE by -1 then you sum up everything and divide by 8.
The same goes for the vertical operator
If your pixels are unsigned chars, you will need to promote them to
ints before passing to the function because the operator requires more
bit space than unsigned chars can provide.
Also the output image will have dimensions (sx-2, sy-2) where sx and sy
are the number of pixels in the x and y directions of your original
image. If you require the output image to have the same size as the
original image then you will need to add the functionality to handle
padding outside the original image.
Hope this helps,
Tony
void sobel( int *a, int sx, int sy, int *out)
{
// (In) a: The image (row major) containing elements of int.
// (In) sx: size of image along x-dimension.
// (In) sy: size of image along y-dimension.
// (Out) out: The output image with dimensions (sx-2, sy-2).
int i, j, ctr = 0;
int *p1, *p2, *p3;
p1 = a; p2 = p1+sx; p3 = p2+sx;
for( j = 0; j < sy-2; ++j )
{
for( i = 0; i < sx-2; ++i )
{
out[ctr++] = ( abs((p1[0] + 2*p1[1] + p1[2]) - (p3[0] + 2*p3[1]+
p3[2])) + abs((p1[2] + 2*p2[2] + p3[2]) - (p1[0] + 2*p2[0] + p3[0])) )
/ 6;
++p1; ++p2; ++p3;
}
p1 += 2; p2 += 2; p3 +=2;
Stop this nonesense right now.
If you use unsigned char ([0, 255]) you will spend most of your time
(and code) handling underflow and overflows. Take for example the top
line of your Sobel kernel, what is -1*100 + 0*50 + 1*50 (in unsigned
char)? It should be a falling edge.
Or even simpler, maybe you are smoothing, what is (100 + 50 + 50 + ...)
/9?
Are you getting no supervision at all? What department are you in?
Engineering? I hope not CS?
You appear to be writing both a rudimentary image proecessing system,
*and* and complex application (number plate recognition and decoding).
If you attempt both together you are only going to learn bad habits and
suffer great disappointment.
Can you please at least develop a simple data structure to hold an
image (nRows, nCols + data buffer is the minimum) and write software to
load, display (writing numbers to a screen will do for a start) and do
simple processing on that. Much better if you can develop a proper C++
class.
Use float or double for the image data --- unless you like making life
extra difficult for yourself.
What image processing books are you reading? None, it would appear.
For a very quick fix, there is a little book by Myler and Weeks, The
Pocket Handbook of Image Processing Algorithms in C, Prentice Hall,
1993. That will give you code + a very simple Image data structure.
Best regards,
Jon C.
erm... why don't you simply replace int* with BYTE * as parameter of the
function then you cast the pixels values to int ?