sightmachine / SimpleCV

The Open Source Framework for Machine Vision
http://simplecv.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 798 forks source link

hueHistogram and histogram are scalled according to min and max non zero hue value #688

Open GintasTr opened 8 years ago

GintasTr commented 8 years ago

If img.hueHistogram, or a basic img.histogram are used with an image which does not cover whole range of 255 hue values, the output histogram is scaled so that minimum non 0 hue value represents histogram [0] and maxmimum non 0 hue value represents histogram [number of bins].

This happens when images are almost uniform in terms of colour, or they are very small, so the range of colours does not cover whole range of hue values. Then hue histogram is shown incorrectly. I believe this is an unintentional feature and might produce incorrect results when used in certain specific conditions.

I believe this happens because, when np.histogram is called, no range argument is passed, thus, quoting the np.histogram description, "range is simply "(a.min(), a.max())". Values outside the range are ignored." Calling the np.historam manually with the addition of argument range=(0.0, 255.0) seems to fix the issue. Attached are histograms of roughly orange (average hue of approximately 11) 20 by 20 pixels image with only single hue peak at ~11.

issue_report