Calculate median/mode but ignore black colour

asked 2019-04-23 16:45:39 -0600

sazr gravatar image

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?
edit retag flag offensive close merge delete

Comments

there is no opencv call in your example. median is not mode and duplicate post

LBerger gravatar imageLBerger ( 2019-04-24 02:23:26 -0600 )edit