Optimized signals_to_img_labels()

This function runs much faster when given a large (>1000) number of regions.
The found speedup factor is around 6 times on the developer's machine.