0

I have color image, elements of which I want to clusterize. I load image:

IColor = cv::imread(path);

and convert it to float(since kmeans takes float mat as input)

IColor.convertTo(IFColor, CV_32FC3, 1 / 255.0);

then I'm trying to prepare input according to my understanding of docs

    int count = IFColor.rows * IFColor.cols;
    cv::Mat points(count * 3, 3, CV_32F), labels;

    points.data = IFColor.data;
    double cmeasure = cv::kmeans(points, 16, labels, cv::TermCriteria(), 3, cv::KMEANS_RANDOM_CENTERS); 

but got some indexing error.

How to perform clustering on color image?

Il'ya Zhenin
  • 1,272
  • 2
  • 20
  • 31
  • "but got some indexing error." <- eradicate the phrase "some error" if you want to become a programmer or any kind of engineer for that matter. Programming (and computers in general) is all about being precise. (1) finding and (2) specifying the exact error in the report are crucial in having a problem solved. – iksemyonov Jun 28 '16 at 14:32
  • 1
    Have a look [here](http://stackoverflow.com/a/34734939/5008845) or [here](http://stackoverflow.com/a/32976883/5008845). And please see [ask] ;D – Miki Jun 28 '16 at 14:39
  • @iksemyonov obiously I made wrong data preparation, and kind of error does not really matters, I believe, since person who is capable of answering this question for a specifiec function with specifiec data input will see what is wrong here. It is logical approach. Error - access violation, anyway. – Il'ya Zhenin Jun 28 '16 at 14:50
  • May work in this exact situation, but you're creating a bad habit for yourself to rely on other people to guess your error. So, don't do that, and teach yourself to specify the error in the report. Will save you time and effort in the future. Not to mention that "some indexing error" looks unprofessional, like as if you couldn't really identify and name the error. – iksemyonov Jun 28 '16 at 14:55
  • @Miki approach in your first link worked for color images, thank you. Found my error too - I've multipleid by number of channels creating mat "points" in its first argument. Without this multiplication it works also. – Il'ya Zhenin Jun 28 '16 at 15:38

0 Answers0