Histogram Based Image Classification with Weka
-
26-04-2021 - |
Question
I am doing a project on histogram based image retrieval, and I need to compare learning algorithms for a set of images. So, in MATLAB, I converted an image (256x256 pixels) into HSV, quantized it to 8(H),3(S),3(V) and created a weighted sum, which is a 256x256 matrix.
I want to use this matrix (of all images in the dataset) to create an ARFF file, and I am stuck at this point. Can anyone help me out with how it has to be done?
Solution
If I understood what you did, you took the image as input (256x256 RGB matrix) and converted it to a 256x256 matrix where each position is a weighted sum of HSV values.
However, if you want to extract a color histogram (which, in this case, is the appropriate input to Weka), you should have as output a vector, where each entry is the count of how many pixels has a given H, S and L value.
Since you have 8 different values for H (0 to 7), 3 for S (0 to 2) and 3 for L (0 to 2), your vector V should have 8+3+3=14 entries. In order to compute V, use the following algorithm:
Input: quantized HSL image I
Output: histogram V
for each pixel p in I:
V[p.H] = V[p.H] + 1 // Increment the count for the H component.
V[7 + p.S] = V[7 + p.S] + 1 // Increment the count for the S component.
V[10 + p.L] = V[10 + p.L] + 1 // Increment the count for the L component.
return V