I am trying to find perimeter of binary object.
Consider following picture
[ 0 0 0 0 1 1 0 ]
[ 0 0 1 0 0 0 0 ]
[ 0 1 1 0 1 1 0 ]
[ 0 1 1 0 0 1 0 ]
[ 0 1 1 1 0 0 0 ]
[ 0 1 0 0 1 1 0 ]
[ 0 0 0 0 1 1 0 ]
Labeled image will look like this
[ 0 0 0 0 1 1 0 ]
[ 0 0 2 0 0 0 0 ]
[ 0 2 2 0 3 3 0 ]
[ 0 2 2 0 0 3 0 ]
[ 0 2 2 0 0 0 0 ]
[ 0 2 0 0 4 4 0 ]
[ 0 0 0 0 4 4 0 ]
Also I collected each object pixels in array list
So for example for 4 marked object the list will be
{ (5,4), (5,5) , (6,4), (6,5) }
Area is just the size of each object pixel array, but how can I find perimeter, should I again iterate over whole image finding neighbors of cell check if it is the corner pixel of the object or there is much easier way to do this just basing on the coordinates.
Please suggest what is the most easier way to find perimeter, any code example will be highly appreciated