Ask Your Question

How do I create a frequency histogram?

asked 2013-07-29 08:59:38 -0600

Willow gravatar image

I have some images of flowers that I have extracted SIFT features from and I clustered the features using K-Means(k=3). I would like to create a "histogram of cluster membership identifiers" to feed to an SVM classifier as described in the accepted answer to the question below.

My question is, how do I create this histogram in Java? Can I use Calchist?

I have a Mat of labels where each element is a cluster index (0...2) for each key point in an image.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-07-29 17:31:07 -0600

You could use calcHist or you could just count how many 0, 1 and 2 you have in each image. You will have a 3D vector, that you should probably normalize by the size of elements. I'm not a Java specialist, but in C++ I will do it with std::count. Or, if you want to make it in one image process, create a vector of size 3, initialize all elements to 0, and for each element of your mat, add 1 to the right vector cell (and normalize at the end).

edit flag offensive delete link more


@Mathieu Barnachon Thanks for your response! Could you tell me the difference between either making it into one image process or counting each image separately? Do they have different effects when classifying?

Willow gravatar imageWillow ( 2013-07-29 18:57:05 -0600 )edit

There is no difference for classification. I think I've been clear enough. I mean, when you quantify your descriptors (aka create the histograms), you have to count how many 0, 1, and 2 you have in your matrix. If you could do it with scan the matrix's values once, it will be better. The complexity in this case is O(n) where n is the number of elements in your matrix. Otherwise, the complexity is O(k*n) where k is the size of the vocabulary (between 100 and 1000 are usual). The idea is to use the pixel value as an index to add one to your histogram. I hope it is more clear now.

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-07-29 21:52:16 -0600 )edit

Question Tools


Asked: 2013-07-29 08:59:38 -0600

Seen: 650 times

Last updated: Jul 29 '13