1 | initial version |
Thanks for the answers and comments, they have been useful.
The problem has been resolved by iterating over the image's pixels manually and keeping only those where the mask's bit is set to white.
I've tried this before but it didn't work. What I've noticed to be the reason, if not other factors as well:
I also had a logical error in the code where I iterated over the pixels of the single-channel mask, as opposed to the three-channel image. This was noticed upon receiving values only for the first channel after colour quantisation.
The two above points seemed to help with more reasonable results. Perhaps there is a better way, and perhaps this method is not completely error-free, it hasn't been tested enough, but hope it would be useful for someone facing similar bugs.
The Mat
object that contained the ROI pixels is not suitable for display where the pixels are not ordered as in the original image. It merely provides a container for all the available colour pixels, which is convenient for the quantisation method.