Augmented Reality: Living on the edge

We’re trying to find the edges in the image. This will help us later to find the glyphs in the image. It will also take away most of the noise around the picture.

The edge is determined by looking to the pixels around the inspected pixel. It is done in 4 directions and we use the maximum difference to find an edge.

Here is the function to do this. Next step: Blob detection!

// Copyright © Alain Bailleul, Alwaysbusy's Corner 2011
public void FindEdges(ABImage EdgeABImage)
{
    int d;
            
    // data pointers
    int src = 0;
    int max = 0;
    int heightMin2 = height - 2;
    int widthMin2 = width - 2;
    byte val255 = (byte) (255 & 0xFF) ;
    byte val0 = (byte) (0 & 0xFF);
          
    // for each line
    for ( int y = 1; y < heightMin2; y++ )
    {
        // for each pixel
        for ( int x = 1; x < widthMin2; x++ )
        {
             src = (y * width + x );
             max = 0;
                    
             // left diagonal
             d =  (imageData[src-width - 1] & 0xFF) - (imageData[src+width + 1] & 0xFF);
             if ( d < 0 )
                 d = -d;
             if ( d > max ) {
                 max = d;
             }
             // right diagonal
             d =  (imageData[src-width + 1] & 0xFF) - (imageData[src+width - 1] & 0xFF);
             if ( d < 0 )
                 d = -d;
             if ( d > max ) {
                 max = d;
             }
             // vertical
             d =  (imageData[src-width] & 0xFF) - (imageData[src+width] & 0xFF);
             if ( d < 0 )
                 d = -d;
             if ( d > max) {
                 max = d;
             }
             // horizontal
             d =  (imageData[src-1]  & 0xFF) - (imageData[src+1] & 0xFF);
             if ( d < 0 )
                 d = -d;
             if ( d > max ) {
                 max = d;
             }                    
             
             //If max is brighter than threshold 40, make it white else make it black
             if (max > 40) {
                 EdgeABImage.imageData[src] = val255;
             }
             else {
                 EdgeABImage.imageData[src] = val0;
             }
        }
   }
}
Advertisements

About Alwaysbusy

My name is Alain Bailleul and I'm the Senior Software Architect/Engineer at One-Two. I like to experiment with new technologies, Computer Vision and A.I. My projects are programmed in B4X , Xojo, C#, java, HTML, CSS and JavaScript. View all posts by Alwaysbusy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: