how to generate a color histogram by concatenating the higher order two bits of each color component

2 次查看(过去 30 天)
I want to use matlab to generate a color histogram. The standard way to do that is to concatenate the higher order two bits for each of the Red (R), Green (G) and Blue (B) values in the RGB space, which forms a 64-bin histogram. I am not quite clear about the concatenating process.
It is easy to generate a histogram for each color channel, but how to concatenate three channels to form one 1-D histogram. In particular, what does the higher order two bits mean? how does that end up with a 64-bin histogram?

回答(3 个)

Guillaume
Guillaume 2016-10-9
I'm not sure where you've seen this standard way. I've never heard of it.
In any case, if I understood correctly:
img = imread('peppers.png'); %demo image
highbits = idivide(img, 64); %only keep the two high bits of each image. Assumes uint8 image
%in R2016b only:
groupedbits = sum(highbits .* permute(uint8([16 4 1]), [1 3 2]), 3);
%in earlier versions:
groupedbits = sum(bsxfun(@times, highbits, permute(uint8([16 4 1]), [1 3 2])), 3);
You can then build your histogram any way you want
histogram(groupedbits, 64, 'BinMethod', 'integers')

Image Analyst
Image Analyst 2016-10-9
Why can't you just concatenate the counts from each color channel together?
rgbImage = imread('peppers.png');
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
countsR = imhist(redChannel, 21);
countsG = imhist(greenChannel, 21);
countsB = imhist(blueChannel, 21);
allThree = [countsR; countsG; countsB]'

Walter Roberson
Walter Roberson 2016-10-9
highred = uint8(floor( double(rgbImage(:, :, 1)) / 2^6));
highgreen = uint8(floor( double(rgbImage(:, :, 2)) / 2^6));
highblue = uint8(floor( double(rgbImage(:, :, 3)) / 2^6));
output = highred * 2^4 + highgreen * 2^2 + highblue;

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by