Ask Your Question

Print histogram values for image in BOW

asked 2014-04-10 11:56:12 -0500

VizGhar gravatar image


I'm working on Bag of words program. I have extracted descriptors for each image via SiftFeatureDetector and SiftDescriptorExtractor into BOWKMeansTrainer as follows:

featureDetector->detect(image, keypoints);
descriptorExtractor->compute(image, keypoints, descriptors);

and runs BOWKMeansTrainer::cluster() and BOWImgDescriptorExtractor::setVocabulary() after. Then I want to see how does the histograms computed via BOWImgDescriptorExtractor looks like for some of the images (reduced code):

bowDE->compute(image, keypoints, histogram);
for (int i = 0; i < histogram.cols; i++)
    cout <<<unsigned>(0, i) << ",";

Result looks like:

{[0,997286537,988897929,1001720295,0,0,1014063753,0, ...]}

(rows=1, cols=count_of_visual_words) So there are either zeros or really huge numbers. Maybe I didn't understand something. How can I correctly print histogram values for given image?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-04-11 02:12:33 -0500

Guanta gravatar image

The histogram is a float-matrix, i.e. you need to call it with .at<float>. Note, the histogram is also normalized in the end, i.e. contains only values between 0 and 1.

edit flag offensive delete link more


Sorry for later response. Many thanks, Just one more question... I want values that shows visual word frequencies (first word occured n-times) not normalized values. Can you tell me how to do it?

VizGhar gravatar imageVizGhar ( 2014-04-15 14:32:08 -0500 )edit

Just multiply the matrix with the number of descriptors (= keypoints.size()) and you'll get the unnormalized histogram back.

Guanta gravatar imageGuanta ( 2014-04-16 02:58:07 -0500 )edit

... I wasn't correct, since the number of keypoints might change due to the internal extraction process you need to use the descriptors-matrix, which you can pass in as optional argument, i.e. :

cv::Mat bow_descs;

bowDE->compute(image, keypoints, histogram, NULL, &bow_descs);

// normalize:

histogram *= bow_descs.rows

Guanta gravatar imageGuanta ( 2014-04-16 03:09:16 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-04-10 11:56:12 -0500

Seen: 762 times

Last updated: Apr 11 '14