# Calculating the perimeter in binary image

After pre-processing, I can obtain the image like this:

Then, I want to calculate the perimeter of the bottom region (annotated with grey line).

I am making an ImageJ plguin. So I have to implement on my own. (firstly, I have to identify front region (in this case, bottom) and then calculate the perimeter)

Is there any idea or suggestion?

Provided that these are representative images, you can apply a region growing operation, somewhere at the bottom of the image (or with the seed point being user defined) which will help in extracting just the contour you want to measure. It might look something like this:

Then, apply the high pass convolution matrix of:

$$\begin{bmatrix} 1 & 1 & 1 \\ 1& -8 & 1 \\ 1 & 1 & 1 \end{bmatrix}$$

Which will get rid of areas of constant "amplitude" and leave only the sharp transition of the perimeter. The image now might look like:

Now you can either just count the white pixels (there are 2658 in this one) or trace the white curve (again, a form of region growing) by starting from one of the points for which the above convolution kernel provided a high output (that is, one of the points that is exactly on the perimeter) recursively by looking for 8-connected components.

Obviously, tracing the curve will provide a much more accurate estimate because there, you can take into account the $\sqrt{2}$ distances of pixels resting on a diagonal. If you then know your pixel size, you can also convert the estimate from pixel space to actual units of length.

Hope this helps.

(All processing done in GIMP, some white pixels outside of the perimeter where detected as well but can be easily taken out manually (even in ImageJ) or, if tracing the curve would not affect the measurement.)