Search code examples
javaalgorithmimage-processingimage-recognitionpattern-recognition

Contour and perimeter recognition in binary image


I need to detect contour (object) and find the perimeter of a detected object.

For example, I have the following image:

enter image description here

All images are binary, so they consist of only 0 and 1.

I need to firstly detect objects, and then find the perimeter of the object contour, the area will be known I guess because this is just the sum of all object pixels.

I am using 4-pixel coherence while finding objects.

I have found some algorithms, but cannot figure out how they work and how to implement them if I have an array of 1 and 0.

Please, can someone provide explanation or code example of the easiest to understand the algorithm.

I need to do this without using OpenCV or any other library.


Solution

  • Here is what you can do:

    1. Small opening in order to erase all the small patterns.
    2. Connected component labeling in order to detect, label and separate your objects. See here for java codes.
    3. Perimeter extraction (each non null pixel with at least one black neighbor).