Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Kmeans segmentation

$
0
0
I have done a kmeans on an image for segmentation and now I want to restore the colors of the centers in the segmented image (for better visualization): cv::Mat image = cv::imread(argv[1]); cv::Mat fImage; image.convertTo(fImage, CV_32F); fImage = fImage.reshape(3, image.cols * image.rows); cv::Mat labels; cv::Mat centers; cv::kmeans(fImage, 10, labels, cv::TermCriteria(), 3, cv::KMEANS_RANDOM_CENTERS, centers); cv::Mat segmented = labels.reshape(1, image.rows); segmented.convertTo(segmented, CV_8UC3); but `segmented` contains just the indexes in the `centers`. Is there a fast way to replace the values of `segmented` by the values of `centers`? I know I can do the for loop in for loop to replace the values, but I thought of something like `LUT`; unfortunately, this runs only on 256 `lut` Mat, but `centers` is not a 256 one channel Mat. Is there another way to do it?

Viewing all articles
Browse latest Browse all 41027

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>