In English, this is what I'm currently doing to separate my image into sub-images:
- Use flood fill to iterate the image and get a list of 'islands' - individual blocks of pixels fully surrounded by transparency.
- Now for each island, make a box around it. Collect these boxes in a list.
- Now check for intersections between the boxes, and join any intersections. Then stop checking, and start again from the start of the list.
- Now make a sub-image for each box and, iterating one last time, save each one of them to the specified output directory.
However, this is really inefficient, and takes at least 10s for a 5MP image on my unoptimised Node implementation of this process. How would I make this process more efficient and arbitrarily multithreaded, while still achieving the same end result?