White pixels have Saturation, S = 0
. So, it is very easy to remove the white pixels from being counted while creating histogram. Do the following:
- Convert your image from
BGR
toHSV
- Then split your
HSV
image into three individual channels i.e.H
,S
andV
- Then, access each pixel of channel
S
and if the pixel value = 0 (means S = 0) then it mean that it is a white pixel. - If the pixel is white then do not consider its Hue value to create histogram and if not...then put its hue value into the corresponding bin (normal procedure to build histogram).
Summary: you just need to find white pixels by checking their Saturation value, which is S = 0
.
PS: Have a look at this link to understand the HSV model.