Slicing clusters of non-black pixels from an image into separate images
It seems that you're just trying to find the connected components of a graph. In this case, the vertices are the non-black pixels and there's an edge between two pixels if they're at distance at most&nbsp;$d$, for some appropriate choice of&nbsp;$d$ and some appropriate metric (Euclidean distance, Manhattan distance, whatever works best).

(Note that, in terms of implementation, you don't need to construct an explicit data structure for the graph; you can calculate whether there's an edge between any two vertices whenever you need to.)