Histogram of HSV quantized image

Hi i want to share with you the results of an HSV quantized image Histogram
i used an image 256X384 converted it into HSV and quantized it into (8X3X3) for H, S and V respectively and after that i made a weighted sum G= 9*H + 3*S + 3*V for this matrix i used this function:
histG=imhist(G,72)
but the output is like that:
histG =
2820
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
13500
is this ok or i have something wrong ? if it is right please explain to me why i got this output.
Thank you

1 Commento

can you please provide full code from reading image to until quntization?

Accedi per commentare.

 Risposta accettata

G= 9*H + 3*S + 3*V
is the wrong weighted sum. You want to add V, not 3*V .
It appears that only the low bin and the high bin are being used in the histogram, as if you had an error in your quantization that led to the results always being either (0,0,0) or the maximum value (8,3,3). The V vs 3*V would not account for this, but a quantization mistake would. Or, alternately, you might have good quantization but a black and white image is being quantized.

7 Commenti

yasmine
yasmine il 26 Dic 2011
sorry yes i wrote it wrongly
i made it G= 9*H + 3*S + V but it gives me the same output
yasmine
yasmine il 26 Dic 2011
no am using RGB images.
here is the quantization am using:
%Quantizing the HUE
for row=1:BRows
for col=1:BCols
if (Hueblock11(row,col) <= 316 && Hueblock11(row,col) <= 20)
Hueblock11(row,col) = 0;
elseif (Hueblock11(row,col) >= 20 && Hueblock11(row,col) <= 40)
Hueblock11(row,col) = 1;
elseif (Hueblock11(row,col) >= 40 && Hueblock11(row,col) <= 75)
Hueblock11(row,col) = 2;
elseif (Hueblock11(row,col) >= 75 && Hueblock11(row,col) <= 155)
Hueblock11(row,col) = 3;
elseif (Hueblock11(row,col) >= 155 && Hueblock11(row,col) <= 190)
Hueblock11(row,col) = 4;
elseif (Hueblock11(row,col) >= 190 && Hueblock11(row,col) <= 270)
Hueblock11(row,col) = 5;
elseif (Hueblock11(row,col) >= 270 && Hueblock11(row,col) <= 295)
Hueblock11(row,col) = 6;
elseif (Hueblock11(row,col) >= 295 && Hueblock11(row,col) <= 316)
Hueblock11(row,col) = 7;
end
end %for col
end %for row
%figure(k+1), subplot(3,2,1), image(HistH1);
%figure(k+2), subplot(3,2,i), imshow(h);
% Quantizing of Saturation
for row=1:BRows
for col=1:BCols
if (Satblock1(row,col) >= 0 && Satblock1(row,col) <= 0.2)
Satblock1(row,col) = 0;
elseif (Satblock1(row,col) >= 0.2 && Satblock1(row,col) <= 0.7)
Satblock1(row,col) = 1;
elseif (Satblock1(row,col) >= 0.7 && Satblock1(row,col) <= 1)
Satblock1(row,col) = 2;
end % end of if
end % for col
end %for row
%Quantizing of Value
for row=1:BRows
for col=1:BCols
if (Valblock1(row,col) >= 0 && Valblock1(row,col) <= 0.2)
Valblock1(row,col) = 0;
elseif (Valblock1(row,col) >= 0.2 && Valblock1(row,col) <= 0.7)
Valblock1(row,col) = 1;
elseif (Valblock1(row,col) >= 0.7 && Valblock1(row,col) <= 1)
Valblock1(row,col) = 2;
end % end of if
end % for col
end %for row
Your first condition,
if (Hueblock11(row,col) <= 316 && Hueblock11(row,col) <= 20)
is incorrect, as it is equivalent to Hueblock11(row,col) <= 20
I do not know what your maximum value for Hueblock11() is, but I speculate that you are intending hue angles, in which case you likely want to be checking the range 316 to 360, and 0 to 20.
Your "if" chain is also faulty in that you include the boundary conditions on both the upper end of one range and the lower end of the next range.
You could achieve much greater efficiency by using histc() calls with no loops.
yasmine
yasmine il 26 Dic 2011
i got your first point but would you explain using example the second point?
Thank you
yasmine
yasmine il 26 Dic 2011
if (Hueblock11(row,col) >= 316 && Hueblock11(row,col) <= 360 && Hueblock11(row,col) >= 0 && Hueblock11(row,col) <= 20)
Hueblock11(row,col) = 0;
is that true for the first point ?(i was trying to cover the range from(316 to 20))
Do not modify HueBlock11 "in place": create a new output matrix.
Hbins = [0 20 40 75 ... 316 inf]);
Ht = histc(HueBlock11, Hbins)
H = Ht(1:end-2);
H(1) = H(1) + Ht(end-1);
Those last two lines are to put 316 upward in to the same bin as less than 20
Look at your code:
if (Hueblock11(row,col) <= 316 && Hueblock11(row,col) <= 20)
Hueblock11(row,col) = 0;
elseif (Hueblock11(row,col) >= 20 && Hueblock11(row,col) <= 40)
Hueblock11(row,col) = 1;
Now what if Hueblock11(row,col) is 20 _exactly_ ? That matches the first condition, but it also matches the second condition. The bin chosen then becomes a matter of the order you coded the tests, which is not robust. If you want the first bin to include 20 exactly, then do not have the second bin include 20 exactly in its range.

Accedi per commentare.

Più risposte (1)

yasmine: If you use imhist on floating point arrays, they need to be normalized in the range 0-1. I suggest you use hist() instead of imhist() - it doesn't have that requirement.
[pixelCounts binValues] = hist(G, numberOfBins);

21 Commenti

yasmine
yasmine il 26 Dic 2011
actually, the G matrix values are integers but greater than 1
min value= 0, max value=30
i tried to use the hist() but gave me same output also
Can you upload your image to tinypic.com so we can try your code?
We would also need the code that constructs the original Hueblock11, Satblock1, and Valblock1.
Well what did you do? Because if you start with a uint8 RGB image, and use code like this:
hsvImage = rgb2hsv(rgbImage);
H = hsvImage(:,:,1); % H is double in range 0-1
S = hsvImage(:,:,2); % S is double in range 0-1
V = hsvImage(:,:,3); % V is double in range 0-1
G = 9*H + 3*S + V; % G is double in range 0-13
[pixelCount, hueValues] = imhist(H);
then H, S, V, and G will all be double. H will be in the range 0-1, G will be in the range 0-13, and the histogram (pixelCount) will be continuous, not just in the first and last bin.
The 256X384 size and the (8,3,3) (72 bin) quantization scheme are fairly tied to a particular CBIR paper in which hue expressed in "degrees".
The documentation for rgb2hsv does not explicitly talk about return types when RGB images are being processed (only when a colormap is being processed.) Unfortunately I cannot test at the moment.
From the histogram, both imhist and hist, it's clear that, for some reason G is binary. It has only two values even though it may be double instead of logical. I think we can only solve this if she gives the actual code.
yasmine
yasmine il 27 Dic 2011
here is one pic:
http://i44.tinypic.com/sqm3o6.jpg
yasmine
yasmine il 27 Dic 2011
i think my main problem is in the quantization of hue as the values of Hueblock11 array before quantization are: min value=0 and max value= 0.9167
so all the values enter in the first if condition
yasmine
yasmine il 27 Dic 2011
Dear Walter Roberson
Do not modify HueBlock11 "in place": create a new output matrix.
Hbins = [0 20 40 75 ... 316 inf]);
Ht = histc(HueBlock11, Hbins)
H = Ht(1:end-2);
H(1) = H(1) + Ht(end-1);
Those last two lines are to put 316 upward in to the same bin as less than 20
please i need a real example.
After your line
hsvimage= rgb2hsv(images);
add
hsvimage(:,:,1) = hsvimage(:,:,1) * 360;
With regard to using histc(), the code I gave is a real example that only needs you to fill in the rest of the Hbins values
yasmine
yasmine il 27 Dic 2011
Thank you so much, i didn know this tip before.
it worked well in quantization
but there is a point and i don know how to fix it:
after multiplying the Hue layer with 360 still the histogram of the Hue is only 2 values
this is before quantization
yasmine
yasmine il 27 Dic 2011
knowing that in saturation and value the histogram is very good using imhist() although the values are double
the values of hue => min =0 , max= 359.4231
the values of saturation => min =0 , max= 1
the values of value => min=0.0392, max=0.9882
What code are you using at present to create the histogram ? If you are using imhist() then you cannot use that, as imhist() expects values to be in the range 0 to 1 (unless the values are uint8 or uint16 data type, which your values would not be.)
yasmine
yasmine il 27 Dic 2011
ok so can i use this method for normalization:
y=(x-min(min(x)))/(max(max(x))-min(min(x)))
x and y are 2D arrays
More simply,
xmin = min(x(:));
y = (x - xmin) ./ (max(x(:)) - xmin);
On the other hand, if you use hist() instead of imhist() then you do not need to do this normalization at all.
yasmine
yasmine il 27 Dic 2011
ok thank you so much
Wait a minute. You accepted Walter's answer but never said what the problem was - why you had only two values in your histogram. I suggested that they were doubles and needed to be in the range 0-1 or else use hist() instead of imhist(). But you said NO, they are integers. Then later you admitted they were in fact doubles. So how did you finally get it to work so that you had values in more than 2 bins?
In the comment after she gave the link for the picture, she did say that before quantization the hues came out min value=0 and max value= 0.9167 -- so indeed not integers. But she probably figured she needed them to be integers as otherwise the 75's and 316's and so on would not be usable. And those values are taken right from the paper so they "had" to be right. Of course she could have divided all those boundary values by 360 and worked in double, but the Inertia of Authority is pretty powerful.
OK fine, but why only two bins?
Naushad Varish
Naushad Varish il 11 Mag 2018
Modificato: Naushad Varish il 11 Mag 2018
Please provide the code. It is still not working properly.
naushad, I'm going to ask you the same thing. Because we gave code and the original poster accepted an answer. So there's no problem here, only with your code.

Accedi per commentare.

Categorie

Scopri di più su Convert Image Type in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by