Using python, how to count area of objects with specified dimensions within an image

Viewed 1156

I am working on data looking at the degeneration of neurites in Neurons derived from human stem cells. The output data is a pair of images, one "before" picture of long, healthy neurites, and one "after" picture of broken, dystrophic neurites. We have an image processing suite that is able to label these neurites, however the software is only able to calculate total neurite area, which does not effectively differentiate between the before and after photos.

I have tried to create an example below. On the left is our "before" picture, with fewer, longer, thicker lines. On the left is the "after" photo with fewer, thinner lines.

Currently, the data output of "area" for pictures "A" and "B" is very similar. I am considering whether it would be possible to write a program which would only count continuous, long object as present in picture A . The final output of the data would just need to be one number for each photo. I.e. photo A may just output "545", vs photo B which could output "33" .

A "before" and B "after"

I can think of versions of object recognition which allow total counting, but can not think of a way to adjust the program to only recognise the longer continous lines rather than the short blobs.

The only reason we prefer to use python is that earlier stages in the processing pipeline use python scripts and we would rather stick to one language if possible. (We also have much more experience in python than matlab).

1 Answers

One simple method would be to filter the image with an edge-detecting filter. You can then do something pretty basic like sum the output, which is a rough measure of the number of edges in the image. Given two images with similar total area, the one with a more "edge-ness" (the norm of the edge-filtered image) would mean that you have more, smaller pieces. One with a smaller filtered output would require fewer, larger pieces. (Again, this assumes similar total area.)

This method has pros and cons. For one, it's incredibly simple. But you'll have to define what you mean by "similar area", to justify comparing the filtered outputs of two images.

Additionally, the edge-filtering method is probably a dramatic underestimate of the actual number of pieces. In the images you've shown here, the additional edges in the right image are only a small fraction of the edges in both images, because the pieces are "split" perpendicular to their long axes. On the other hand, if they were split parallel to their long axes, you'd get roughly twice the amount of edge.

Anyway, if this simple approach doesn't work for you, there are more complex algorithms implemented in scikit-image, which are designed just for this purpose. Check out, for example, the approximate_polygon() method. The skimage.measure module has several different methods for tackling this problem.

Related