I want to implement the following Matlab function:
function hist = binnedRgbHist(im, numChannelBins)
Given an image im
and a number between 1 and 256 numChannelBins
, it should create a histogram sized (numChannelBins)^3
.
For example, if numChannelBins
is 2, it should produce the following 8-sized histogram:
- Number of pixels with
R < 128, G < 128, B < 128
- Number of pixels with
R < 128, G < 128, B >= 128
- Number of pixels with
R < 128, G >= 128, B < 128
- Number of pixels with
R < 128, G >= 128, B >= 128
- Number of pixels with
R > 128, G < 128, B < 128
- Number of pixels with
R > 128, G < 128, B >= 128
- Number of pixels with
R > 128, G >= 128, B < 128
- Number of pixels with
R > 128, G >= 128, B >= 128
It is like creating a cube where each axis represents one of (R,G and B), where each axis is divided into 2 bins => Finally there are 8 bins in the cube.
My questions:
- It there a built-in function for it?
- If not, how is it better to implement it in manners of runtinme using the GPU? Should I better iterate over the pixels once and create the histogram manually, or should I better iterate over the bins and each time count the number of pixels which satisfy the bin's conditions?