Detecting B&W Clusters of Pixels

97 Views Asked by At

I am relatively new to Python and would like some help with some ideas to solve this problem...

I have a black and white image as so: black image with white dots

And essentially need to get the midpoint (or honestly any point, as long as it's consistent across all of the dots) of each of those white dots. The program could spit out a list of coordinate points for each of those dots.

I am doing this because I want to have a list of the distances of each dot from its place to the bottom of the image. I said getting the mid-point doesn't matter, it could be any point as long as it's consistent across the dots because I am comparing the values of one image to the values of another that would be measured in the same way.

I had tried to split the image into rows and then count the number of pixels in each row, but that felt like it was limiting and wouldn't really do the best job.

I was thinking to maybe make a loop that looks at one pixel and then checks to see the pixels around it until it reaches the edge or something like that, but it seems like that would take a lot of computing power even with B&W as I have to run this through hundreds of images that have approximately 10 million pixels.

Possibly a solution related to converting the coordinates of the image into a graph and performing cluster analysis?

1

There are 1 best solutions below

1
On

If you have a binary image, then I think that using skimage to label then get region properties. I think that this tutorial should get you moving on the take you are hoping to accomplish:

https://scikit-image.org/docs/stable/auto_examples/segmentation/plot_regionprops.html