I have spectrograms of certain repeating sounds. The background of the spectrograms are black and could easily be made transparent if that would help. The sounds are easily distinct from the background. As shown below, each sound is a series of connected pixels of various colors.
What I want to do
I would like to separate each of the sounds into separate images or slices. That is, from the above example I would like to isolate the sounds into something like the following example.
If you are familiar with Unity 3D, they do something similar with their "Sprite Slicer" that creates a rectangle around objects on a transparent image.
My attempt of an algorithm
Select non-black pixel For each neighboring pixel If pixel is black Try each non-visited neighboring pixel again, traveling a maximum of three pixels away ( a sort of threshold ) If pixel is non-black Add to a list of significant pixels and travel to neighboring pixels Mark selected pixels as visited and select a new non-black pixel
This would result in a list of lists containing pixels where each list is the extracted sound or cluster of pixels that could be compiled into images.
I know this has been done before and is called something, but for the life of me I cannot find the words to describe it (hence the poor title).
My algorithm feels non-standard and potentially slow and poorly written. It should work, but it's not it.
What is this called, how can I find more about it?
How do I succeed in extracting the sub-images as shown by the example?