使用直方图相似性合并相似区域
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
using namespace cv;
Mat display(Mat& markers, int noOfSegment)
{
vector<Vec3b> colorTab;
for (int i = 0; i < noOfSegment; i++)
{
int b = theRNG().uniform(0, 255);
int g = theRNG().uniform(0, 255);
int r = theRNG().uniform(0, 255);
colorTab.push_back(Vec3b((uchar)b, (uchar)g, (uchar)r));
}
Mat watershedImage(markers.size(), CV_8UC3);
for (int i = 0; i < markers.rows; i++)
{
for (int j = 0; j < markers.cols; j++)
{
int index = markers.at<int>(i, j);
if (index == -1)
watershedImage.at<Vec3b>(i, j) = Vec3b((uchar)255, (uchar)255, (uchar)255);
else if (index <= 0 || index &g