MATLAB: How to obtain a 3D histogram from 3 separate arrays

rida

I have the following code:
img_rgb = imread('IMD037.bmp');
img_gray=rgb2gray(img_rgb);
[rows, cols] = size(img_gray);
%%%Converting image in HSV domain and then calculate Histogram
img_hsv = rgb2hsv(img_rgb);
% % splitting HSV image into h, s & v channels
h = img_hsv(:, :, 1);
s = img_hsv(:, :, 2);
v = img_hsv(:, :, 3);
% quantization levels
h_level=16;
s_level=4;
v_level=4;
% %%%%%%%%%image quantization
max_h=max(h(:));
min_h=min(h(:));
max_s=max(s(:));
min_s=min(s(:));
max_v=max(v(:));
min_v=min(v(:));
range_h=max_h-min_h;
range_s=max_s-min_s;
range_v=max_v-min_v;
%%%%%%%%%%%%%%FOR Hue
scale_h=(h_level-1)/range_h;
%q=round(x*scale)/scale;


for row = 1:size(h, 1)
for col = 1 : size(h, 2)
quantizedValueForH(row, col) = ceil(h(row, col)*scale_h);
end
end
%%%%%%%%%%%%%%%For Saturation
scale_s=(s_level-1)/range_s;
%q=round(x*scale)/scale;
for row = 1:size(s, 1)
for col = 1 : size(s, 2)
quantizedValueForS(row, col) = ceil(s(row, col)*scale_s); % 16*h(i,j)/max of h

end
end
%%%%%%%%%%%%%%%%For Value
scale_v=(v_level-1)/range_v;
%q=round(x*scale)/scale;
for row = 1:size(s, 1)
for col = 1 : size(s, 2)
quantizedValueForV(row, col) = ceil(s(row, col)*scale_v); % 16*h(i,j)/max of h
end
end
%%%%%Histogram
figure
%vec_bin_edges=0:15;
%hist3([quantizedValueForH quantizedValueForS], {0 15});
hist(quantizedValueForH)
figure
hist(quantizedValueForS)
figure
hist(quantizedValueForV)

Best Answer

You can use scatter3 like in my attached demo. But this is not a true 3D visualization because I just put a "dot" at the (R, G, B) location if there is a pixel with that color. To do a true 3D you'd have to associate each location with an intensity that represents how many pixels had that exact color. Nonetheless, it's probably good enough for what you want.
If you want a better 3D color gamut visualizer, like this:
, let me know. It's a bit tricky but can be done.