Ask Your Question

Revision history [back]

these lines are wrong

  new_image.at<Vec3b>(y,x)[0] = centers.at<int>(cluster_idx, 0);
  new_image.at<Vec3b>(y,x)[1] = centers.at<int>(cluster_idx, 1);
  new_image.at<Vec3b>(y,x)[2] = centers.at<int>(cluster_idx, 2);

size image is

Mat new_image(src.rows * src.cols, 3, CV_32S);

and loop limit are

  for( int y = 0; y < src.rows; y++ )
    for( int x = 0; x < src.cols; x++ )

these lines are wrong

  new_image.at<Vec3b>(y,x)[0] = centers.at<int>(cluster_idx, 0);
  new_image.at<Vec3b>(y,x)[1] = centers.at<int>(cluster_idx, 1);
  new_image.at<Vec3b>(y,x)[2] = centers.at<int>(cluster_idx, 2);

size image is

Mat new_image(src.rows * src.cols, 3, CV_32S);

and loop limit are

  for( int y = 0; y < src.rows; y++ )
    for( int x = 0; x < src.cols; x++ )

read this post about kmeans