Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Calculate median/mode but ignore black colour

In OpenCV Python, I have masked out parts of the image, thus they are black. I need to calculate the median (or mode) colour that occurs in the image but ignore the masked/black pixels.

How can I do this because the functions I use still consider black pixels AFAIK:

mode = scipy.stats.mode(img) # will consider black pixels wont it?
median = np.median(img, axis=(0,1)) # will consider black pixels wont it?