@@ -315,13 +315,19 @@ void Slic::display_contours(cv::Mat &image, cv::Vec3b colour) {
315315 * Output: -
316316 */
317317void Slic::colour_with_cluster_means (cv::Mat &image) {
318- vector<cv::Vec3b> colours (centers.rows );
319-
318+ vector<cv::Vec3i> colours (centers.rows );
319+ /* fill */
320+ for (size_t i = 0 ; i < colours.size (); i++) {
321+ colours[i] = cv::Vec3i (0 , 0 , 0 );
322+ }
320323 /* Gather the colour values per cluster. */
321324 for (int i = 0 ; i < image.cols ; i++) {
322325 for (int j = 0 ; j < image.rows ; j++) {
323326 int index = clusters (i,j);
324- colours[index] += image.at <cv::Vec3b>(j, i);
327+ cv::Vec3b c = image.at <cv::Vec3b>(j, i);
328+ colours[index][0 ] += (c[0 ]);
329+ colours[index][1 ] += (c[1 ]);
330+ colours[index][2 ] += (c[2 ]);
325331 }
326332 }
327333
@@ -333,7 +339,8 @@ void Slic::colour_with_cluster_means(cv::Mat &image) {
333339 /* Fill in. */
334340 for (int i = 0 ; i < image.cols ; i++) {
335341 for (int j = 0 ; j < image.rows ; j++) {
336- image.at <cv::Vec3b>(j, i) = colours[clusters (i,j)];;
342+ cv::Vec3i c = colours[clusters (i,j)];
343+ image.at <cv::Vec3b>(j, i) = cv::Vec3b (c[0 ], c[1 ], c[2 ]);
337344 }
338345 }
339346}
0 commit comments