1 | initial version |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
2 | No.2 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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;
}
good luck !
3 | No.3 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
4 | No.4 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
5 | No.5 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
6 | No.6 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
7 | No.7 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
8 | No.8 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
9 | No.9 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
10 | No.10 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
11 | No.11 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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 !
12 | No.12 Revision |
here's something to try, after retrieving the K centers using kmeans()
(like above):
Mat showCenters(const Mat ¢ers , 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;
}
good luck !