Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz) { Mat cent = centers.reshape(3, centers.rows); // make a horizontal bar of K color patches: Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0)); for (int i=0; i<centers.rows; i++)="" {="" set="" the="" resp.="" roi="" to="" that="" value="" (just="" fill="" it):="" draw(="" rect(i="" *="" siz,="" 0,="" siz,="" siz))="centers.at&lt;Vec3f">(i,0)); } // optional viz. //imshow("CENTERS", draw); //waitKey(1);

// optional conversion from float back to 8U
// draw.convertTo(draw, CV_8U); 
return draw;

}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz) {
Mat cent = centers.reshape(3, centers.rows);
// make a horizontal bar of K color patches:
Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0));
for (int i=0; i<centers.rows; i++)="" {="" set="" the="" resp.="" roi="" to="" that="" value="" (just="" fill="" it):="" draw(="" rect(i="" *="" siz,="" 0,="" siz,="" siz))="centers.at&lt;Vec3f">(i,0));
i++) {
// set the resp. ROI to that value (just fill it):
draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0));
 }
// optional viz.
//imshow("CENTERS", draw);
//waitKey(1);

//waitKey(1);
 // optional conversion from float back to 8U
 // draw.convertTo(draw, CV_8U);
 return draw;
}

}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz) {
     Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0));
    for (int i=0; i<centers.rows; i++) {
          // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0));
    }
    // optional viz.
    //imshow("CENTERS", draw);
    //waitKey(1);

    // optional conversion from float back to 8U
    // draw.convertTo(draw, CV_8U); 
    return draw;
}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz) {
    Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0));
    for (int i=0; i<centers.rows; i++) {
          // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0));
centers.at<Vec3f>(i,0);
    }
    // optional viz.
    //imshow("CENTERS", draw);
    //waitKey(1);
//waitKey();

    // optional conversion from float back to 8U
    // draw.convertTo(draw, CV_8U); 
    return draw;
}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz) {
    Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0));
    for (int i=0; i<centers.rows; i++) {
          // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0);
    }
    // optional viz.
    //imshow("CENTERS", draw);
    //waitKey();

    // optional conversion from float back to 8U
    // draw.convertTo(draw, //draw.convertTo(draw, CV_8U); 
    return draw;
}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz) siz=64) {
    Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0));
    for (int i=0; i<centers.rows; i++) {
          // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0);
    }
    // optional viz.
    //imshow("CENTERS", draw);
    //waitKey();

    // optional conversion from float back to 8U
    //draw.convertTo(draw, CV_8U); 
    return draw;
}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz=64) {
    Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0));
    for (int i=0; i<centers.rows; i++) {
          // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0);
    }
    // optional viz.
    //imshow("CENTERS", draw);
    //waitKey();

    // optional conversion from float back to 8U
    //draw.convertTo(draw, CV_8U); 
    return draw;
}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz=64) {
    Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0));
    for (int i=0; i<centers.rows; i++) {
         // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0);
    }
    // optional viz.
    //imshow("CENTERS", draw);
    //waitKey();

    // optional conversion from float back to 8U
8U (if you want to imwrite() it)
    //draw.convertTo(draw, CV_8U); 
    return draw;
}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz=64) {
    Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0));
    for (int i=0; i<centers.rows; i++) {
         // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0);
    }
    draw.convertTo(draw, CV_8U); 

    // optional viz.
visualization:
    //imshow("CENTERS", draw);
    //waitKey();

    // optional conversion from float back to 8U (if you want to imwrite() it)
    //draw.convertTo(draw, CV_8U); 
    return draw;
}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz=64) {
    Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * centers.rows, centers.type(), Scalar::all(0));
    for (int i=0; i<centers.rows; i++) {
         // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0);
    }
    draw.convertTo(draw, CV_8U); 

    // optional visualization:
    //imshow("CENTERS", draw);
    //waitKey();

    //imwrite("centers.png", draw);

    return draw;
}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz=64) {
    Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * centers.rows, centers.type(), cent.rows, cent.type(), Scalar::all(0));
    for (int i=0; i<centers.rows; i<cent.rows; i++) {
         // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = centers.at<Vec3f>(i,0);
cent.at<Vec3f>(i,0);
    }
    draw.convertTo(draw, CV_8U); 
CV_8U);

    // optional visualization:
    //imshow("CENTERS", imshow("CENTERS", draw);
    //waitKey();
waitKey();

    //imwrite("centers.png", draw);

    return draw;
}

good luck !

here's something to try, after retrieving the K centers using kmeans() (like above):

Mat showCenters(const Mat &centers , int siz=64) {
    Mat cent = centers.reshape(3, centers.rows);
    // make  a horizontal bar of K color patches:
    Mat draw(siz , siz * cent.rows, cent.type(), Scalar::all(0));
    for (int i=0; i<cent.rows; i++) {
         // set the resp. ROI to that value (just fill it):
         draw( Rect(i * siz, 0, siz, siz)) = cent.at<Vec3f>(i,0);
    }
    draw.convertTo(draw, CV_8U);

    // optional visualization:
    imshow("CENTERS", draw);
    waitKey();

    //imwrite("centers.png", draw);

    return draw;
}

image description good luck !