I need help processing a biology bacteria picture. I just started learning Mathematica and I hope you guys can use a simple method to help me solve the problem, please do not use super complicated methods.
Below is what I want to do, it was done by my friend and he refuses to teach me. I want to label each bacteria cell on the picture with numbers.
My thoughts are as follows:
- Binarize the image and use
ComponentMeasurements
to find the centroids of all bacteria cells. - Convert the centroids (coordinates) to numbers 1 to 12 and make it into a graphic.
- Show my original picture together with the picture numbered 1 to 12 to get my end result.
However, my problem is that I do not know how to convert centroids (which are coordinate positions) into numbers.
Thanks Simon Woods! Here is my code and my attempt. Please correct me and see which part am I wrong.
Firstly, This is the picture I started off with (named "bacteria") and I want it to be labelled as shown on the above picture.
And this is my code. I did not include how I sharpen and binarize the picture because it is quite straightforward. I will only start with the part whereby I get the centroids. i named my binarized picture as "image".
morpData = MorphologicalComponents[image]
Tally@Flatten@morpData
cenData = ComponentMeasurements[morpData, {"Centroid"}]
getCenData = centroidData[[All, 2, 1]]
After these 4 steps, I managed to get the list of centroid coordinates which are
{{483.727, 478.227}, {422., 442.5}, {289.862, 331.534}, {245.261, 299.542}, {140.959, 259.041}, {404.427, 224.821}, {538.261, 223.39}, {56., 174.192}, {41., 140.844}, {190.529, 95.6238}, {277.262, 65.4048}, {491.833, 34.2778}}
This is good because I managed to identify all 12 bacteria in the picture. However, I need to know how to convert centroid coordinates to labeled numbers!!
I tried, but I still cannot do it. And to prove that I really tried, this is my latest effort at trying to convert the 12 centroid coordinates into numbering and overlay with the original image. Please tell me where I went wrong:
Show[bacteria,Map[Graphics[Text[Style[getCenData[[1]], Red], getCenData[[2]]]], getCenData]]
And please, do not tell me to convert one by one, that is too troublesome.
{"Centroid"}
) and then just useText @@@ cenData
$\endgroup$