Thursday, December 11, 2014

Analyze: Pixel connectivity - Part II



Second part about pixel connectivity. How to precisely measure a length by counting pixels with Analyze > Analyze Particles... ?



1- Playing with circles

When two pixels are in contact edge to edge, the distance between them is 1 pixel, otherwise if they are in contact by a corner, the distance is  √2.
The best approach is to count the number of edge and corner contacts. However, such a tool doesn't exist in ImageJ and programming a macro/script for that is beyond the scope of this post.

An easier approach is to calculate an average length and this can be done with a circle (Fig.1).

Fig.1: 256x256 8-bit image with a black circle (diameter 100) and a close-up view showing the pixels connected by their edges.

To create this circle, go to...
  • File > New > Image..., and create a 256x256 8-bit image with a white background
  • Draw a circle using the circle tool (tool #2) of radius 50 (diameter=100) and Edit > Draw in black color (use the color chooser and reset the fore- and background colors).
  • Then zoom in to observe the connectivity. All the pixels are connected by their edges corresponding to a 4-connectivity.
  • Finally, count the number of pixels by running Analyze > Analyze Particles... and look at the Area column.

Fig.2: Close-up view of the circle of Fig.1 after skeletonization. The pixel connectivity is now 8.
  • To get a 8-pixel connectivity, duplicate the Circle image and run a skeletonization with Process > Binary > Skeletonize.
  • Zoom in and look at the connectivity. Now, we have a 8-pixel connectivity.
  • Run, the Analyze > Analyze Particles...

The table (Fig. 3) shows the different values of Area obtained with 4- and 8-pixel connectivity, respectively.

Fig.3: Results

The Area values of Fig.3 must be compared to the exact perimeter of the circle which is equal to pi * D = 314 pixels.

From the results of the Analyze > Analyze Particles..., we can compute a weighting factor of:

400/314 = 1.273

and

281/314 = 0.89 ≈ 0.90 (found in the literature)

In conclusion, you need to apply this weighting factor - choose the coefficient in function of the pixel connectivity - if you want a good approximation of the length of your sample.


Hope that helps!

2. Other crazybiocomputing posts

Further readings are available in ...
  • Analysis Series  [Link]
  • Image Processing TOC [Link]

No comments:

Post a Comment