Friday, December 5, 2014

Measuring the length of a sample

One of the simplest parameter to measure in a segmented - binary - image is the length of your sample (a molecule, cellular or subcellular components, fibers, etc.).
I'll describe two techniques (manual and automatic) to get such information.

Before doing any measurements, you need a binary image. Thus, the various steps of image processing (enhance brightness/contrast,  filters, subtract background, etc.) and of segmentation must be used to get a clean and (almost) perfect partitioned image ready to the analysis of image features.

1- Objects of any shape

If there is no assumption about the object's shape, two approaches are possible...
The image of Fig. 1 is a simple example of a segmented sample.

Fig.1: Test image with the handwritten word 'crab'

1-1- Drawing the medial axis
The simplest (and naive) way for obtaining the object's length is to draw a line following the medial axis of the shape. This can be done with the Segmented Line tool (Tool # 5, right-click and choose item #2 - you may choose another sub-tool like FreeHand Line).

Fig.2: Drawing the medial axis 
Once the path is drawn, compute a Analyze > Plot Profile, click on the List button and read the last row index. This is the length of your profile. In my case, I found 1063 pixels.

1-2- Area of medial axis
The previous technique is possible only if you have one sample, but for a series of images that's too time consuming and not reproducible (that's really difficult to draw twice the same line).
To extract the medial axis of an object of interest, there is a morphological operation [see post] termed skeletonization available in Process > Binary > Skeletonize. This is a kind of erosion leading to a line of one pixel wide.

Fig. 3: Skeleton (median axis) of the 'crab' text
Counting the number of pixels in the skeleton corresponds to the 'crab' length. Run a Analyze > Analyze Particles... and look at the Area column, the value is expressed in pixels. In my case, I got 967 pixels.
This value is smaller than the manual approach because, their paths are not exactly the same specially in the 'turns' and in the ends (Fig.4).

Fig 4: Superimposition of the skeleton on the original image. The blue circles highlight the paths differences with respect to Fig. 2.

2- Object of uniform width

2-1-By selection
If the object has a uniform width, we can use the wand (Tool # 8), click somewhere in the image (the text is selected by a yellow line) and convert this closed yellow selection area to a line in Edit > Selection > Area to Line . Finally, compute a plot profile, the last row index roughly corresponds - here - to the double of length.

2-3- Perimeter in Analyze Particles...
Based on the same principle, check Perimeter in Analyze > Set Measurements... and run Analyze > Analyze Particles... Then, read the value corresponding to the perimeter. Assuming a constant width, the length may be deduced:
Perimeter = 2 * Width + 2 * Length 
Length = (Perimeter - 2 * Width) / 2

In this example, I estimate the width by using the line tool in several parts of the object ... and I found 10.5 pixels. Thus, the length is evaluated to (2211-2*10.5)/2 = 1095 pixels something comparable to the segmented line approach.
Note: Compared to the length, the width is negligible and the length is roughly equal to Perimeter / 2.0.

3- Conclusion

The Skeletonize method is the best approach for analyzing a great number of objects and use the drawing line for a try or only if you can't extract (segment) the object of interest. Moreover, if you need some statistics (lengths comparison), don't mix both methods (drawing path and skeletonize) during your session, because your results couldn't be comparable.
The next step is the measurement of the other dimension parameter: the width [Link].

No comments:

Post a Comment