1

I'm searching for a program which detects the border of a image, for example I have a square and the program detects the X/Y-Coords

Example:

alt text http://img709.imageshack.us/img709/1341/22444641.png

mdb
  • 52,000
  • 11
  • 64
  • 62
user237060
  • 2,599
  • 4
  • 18
  • 7
  • 1
    border != xy coordinates. Please clarify your question. Also, what language(s) and platform(s) are you asking about? –  Dec 23 '09 at 19:22
  • 1
    It's more like SVG, it want to have the outer coords/borders of the graphical element; ![alt text][1] [1]: http://img31.imageshack.us/img31/5449/76190433.png – user237060 Dec 23 '09 at 19:30
  • NOTE: I don't want code, I want more a program! – user237060 Dec 23 '09 at 19:33
  • 3
    Could you give more details regarding what images you want to deal with? points you should refer to: are they all going to be such black/white images, good quality, the rectangle being exactly aligned vertically|horizontally, will it be an EXACT rectangle? ... – elijah Dec 23 '09 at 19:42

5 Answers5

5

This is a very simple edge detector. It is suitable for binary images. It just calculates the differences between horizontal and vertical pixels like image.pos[1,1] = image.pos[1,1] - image.pos[1,2] and the same for vertical differences. Bear in mind that you also need to normalize it in the range of values 0..255.

But! if you just need a program, use Adobe Photoshop.

Code written in C#.

public void SimpleEdgeDetection()
{
    BitmapData data = Util.SetImageToProcess(image);
    if (image.PixelFormat != PixelFormat.Format8bppIndexed)
        return;

    unsafe
    {
        byte* ptr1 = (byte *)data.Scan0;
        byte* ptr2;
        int offset = data.Stride - data.Width;
        int height = data.Height - 1;
        int px;

        for (int y = 0; y < height; y++)
        {
            ptr2 = (byte*)ptr1 + data.Stride;
            for (int x = 0; x < data.Width; x++, ptr1++, ptr2++)
            {
                px = Math.Abs(ptr1[0] - ptr1[1]) + Math.Abs(ptr1[0] - ptr2[0]);
                if (px > Util.MaxGrayLevel) px = Util.MaxGrayLevel;
                ptr1[0] = (byte)px;
            }
            ptr1 += offset;
        }
    }
    image.UnlockBits(data);
}

Method from Util Class

static public BitmapData SetImageToProcess(Bitmap image)
{
    if (image != null)
        return image.LockBits(
            new Rectangle(0, 0, image.Width, image.Height),
            ImageLockMode.ReadWrite,
            image.PixelFormat);

    return null;
}

If you need more explanation or algorithm just ask with more information without being so general.

pb2q
  • 58,613
  • 19
  • 146
  • 147
Andres
  • 3,324
  • 6
  • 27
  • 32
4

It depends what you want to do with the border, if you are looking at getting just the values of the edges of the region, use an algorithm called the Connected Components Region. You must know the value of the region prior to using the algorithm. This will navigate around the border and collect the outside region. If you are trying to detect just the outside lines get the gradient of the image and it will reveal where the lines are. To do this convolve the image with an edge detection filter such as Prewitt, Sobel, etc.

monksy
  • 14,156
  • 17
  • 75
  • 124
4

You can use any image processing library such as Opencv. which is in c++ or python. You should look for edge detection functions such as Canny edge detection. Of course this would require some diving into image processing. The example image you gave should be straight forward to detect, how noisy/varied are the images going to be?

Lin
  • 2,445
  • 5
  • 27
  • 37
  • Canny would be overkill for an image like that. A simple combination of gradient filters would do what he needed. – monksy Dec 23 '09 at 19:23
  • It all depends on what conditions you want to deal with(as mentioned - how noisy is the image going to be) – elijah Dec 23 '09 at 19:28
  • Given his sample shown in the orignal post canny would be overkill – monksy Dec 23 '09 at 23:07
1

A shape recognition algorithm might help you out, providing it has a solid border of some kind, and the background colour is a solid one.

Community
  • 1
  • 1
Chris S
  • 64,770
  • 52
  • 221
  • 239
0

From the sounds of it, you just want a blob extraction algorithm. After that, the lowest/highest values for x/y will give you the coordinates of the corners.

BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
  • Yes, but I think you need first apply a border detector to distinguish object's inner pixels from object's border pixels. – Andres Dec 23 '09 at 19:43
  • Judging from the comments made after my post, it sounds like he has an image like above, and wants the coordinates of the corners of some filled polygon. I guess my next question would be, is it always convex? – BlueRaja - Danny Pflughoeft Dec 23 '09 at 21:14