Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count the number of spots in this image?

I am trying to count the number of hairs transplanted in the following image. So practically, I have to count the number of spots I can find in the center of image. (I've uploaded the inverted image of a bald scalp on which new hairs have been transplanted because the original image is bloody and absolutely disgusting! To see the original non-inverted image click here. To see the larger version of the inverted image just click on it). Is there any known image processing algorithm to detect these spots? I've found out that the Circle Hough Transform algorithm can be used to find circles in an image, I'm not sure if it's the best algorithm that can be applied to find the small spots in the following image though.

enter image description here

P.S. According to one of the answers, I tried to extract the spots using ImageJ, but the outcome was not satisfactory enough:

  1. I opened the original non-inverted image (Warning! it's bloody and disgusting to see!).
  2. Splited the channels (Image > Color > Split Channels). And selected the blue channel to continue with.
  3. Applied Closing filter (Plugins > Fast Morphology > Morphological Filters) with these values: Operation: Closing, Element: Square, Radius: 2px
  4. Applied White Top Hat filter (Plugins > Fast Morphology > Morphological Filters) with these values: Operation: White Top Hat, Element: Square, Radius: 17px enter image description here

However I don't know what to do exactly after this step to count the transplanted spots as accurately as possible. I tried to use (Process > Find Maxima), but the result does not seem accurate enough to me (with these settings: Noise tolerance: 10, Output: Single Points, Excluding Edge Maxima, Light Background):

enter image description here

As you can see, some white spots have been ignored and some white areas which are not actually hair transplant spots, have been marked.

What set of filters do you advise to accurately find the spots? Using ImageJ seems a good option since it provides most of the filters we need. Feel free however, to advise what to do using other tools, libraries (like OpenCV), etc. Any help would be highly appreciated!

like image 397
B Faley Avatar asked Oct 03 '15 17:10

B Faley


People also ask

What is the use of count tool?

The count tool is only found in the extended version of Photoshop. Its main use is in areas such as scientific and medical imaging, where it is useful for recording the number of items that appear in a particular image.


1 Answers

I do think you are trying to solve the problem in a bit wrong way. It might sound groundless, so I'd better show my results first.

Below I have a crop of you image on the left and discovered transplants on the right. Green color is used to highlight areas with more than one transplant.

enter image description here

The overall approach is very basic (will describe it later), but still it provides close to be accurate results. Please note, it was a first try, so there is a lot of room for enhancements.

Anyway, let's get back to the initial statement saying you approach is wrong. There are several major issues:

  1. the quality of your image is awful
  2. you say you want to find spots, but actually you are looking for hair transplant objects
  3. you completely ignores the fact average head is far from being flat
  4. it does look like you think filters will add some important details to your initial image
  5. you expect algorithms to do magic for you

Let's review all these items one by one.

1. Image quality

It might be very obvious statement, but before the actual processing you need to make sure you have best possible initial data. You might spend weeks trying to find a way to process photos you have without any significant achievements. Here are some problematic areas:

enter image description here

I bet it is hard for you to "read" those crops, despite the fact you have the most advanced object recognition algorithms in your brain.

Also, your time is expensive and you still need best possible accuracy and stability. So, for any reasonable price try to get: proper contrast, sharp edges, better colors and color separation.

2. Better understanding of the objects to be identified

Generally speaking, you have a 3D objects to be identified. So you can analyze shadows in order to improve accuracy. BTW, it is almost like a Mars surface analysis :)

enter image description here

3. The form of the head should not be ignored

Because of the form of the head you have distortions. Again, in order to get proper accuracy those distortions should be corrected before the actual analysis. Basically, you need to flatten analyzed area.

enter image description here

3D model source

4. Filters might not help

Filters do not add information, but they can easily remove some important details. You've mentioned Hough transform, so here is interesting question: Find lines in shape

I will use this question as an example. Basically, you need to extract a geometry from a given picture. Lines in shape looks a bit complex, so you might decide to use skeletonization

enter image description here

All of a sadden, you have more complex geometry to deal with and virtually no chances to understand what actually was on the original picture.

5. Sorry, no magic here

Please be aware of the following:

enter image description here

You must try to get better data in order to achieve better accuracy and stability. The model itself is also very important.

Results explained

As I said, my approach is very simple: image was posterized and then I used very basic algorithm to identify areas with a specific color.

enter image description here

Posterization can be done in a more clever way, areas detection can be improved, etc. For this PoC I just have a simple rule to highlight areas with more than one implant. Having areas identified a bit more advanced analysis can be performed.

Anyway, better image quality will let you use even simple method and get proper results.

Finally

How did the clinic manage to get Yondu as client? :)

enter image description here

Update (tools and techniques)

  • Posterization - GIMP (default settings,min colors)
  • Transplant identification and visualization - Java program, no libraries or other dependencies
  • Having areas identified it is easy to find average size, then compare to other areas and mark significantly bigger areas as multiple transplants.

Basically, everything is done "by hand". Horizontal and vertical scan, intersections give areas. Vertical lines are sorted and used to restore the actual shape. Solution is homegrown, code is a bit ugly, so do not want to share it, sorry.

The idea is pretty obvious and well explained (at least I think so). Here is an additional example with different scan step used:

enter image description here

Yet another update

A small piece of code, developed to verify a very basic idea, evolved a bit, so now it can handle 4K video segmentation in real-time. The idea is the same: horizontal and vertical scans, areas defined by intersected lines, etc. Still no external libraries, just a lot of fun and a bit more optimized code.

enter image description here

enter image description here

Additional examples can be found on YouTube: RobotsCanSee

or follow the progress in Telegram: RobotsCanSee

like image 77
Renat Gilmanov Avatar answered Sep 29 '22 00:09

Renat Gilmanov