Borrar filtros
Borrar filtros

How can I obtain a 3D histogram from 3 separate arrays?

1 visualización (últimos 30 días)
Rida
Rida el 22 de Mzo. de 2014
Comentada: Rida el 23 de Mzo. de 2014
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)

Respuesta aceptada

Image Analyst
Image Analyst el 22 de Mzo. de 2014
Editada: Image Analyst el 22 de Mzo. de 2014
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.
  1 comentario
Rida
Rida el 23 de Mzo. de 2014
Thanks for your answer Sir
I am actually trying to count probability of each of the entry in H,S,V
such as when quantizedValueForH=0, quantizedValueForS=0, quantizedValueForV=0 the value at of another 16x4x4 matrix at 1,1,1 will be incremented. If the value is quantizedValueForH=4,quantizedValueForS=0,quantizedValueForV=1 the value at 5,1,2 will be incremented and so on, therefore I tried to make 3D histogram but that's not the right way I guess.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by