25 if (inimg.rows != outimg.rows || inimg.cols != outimg.cols || inimg.type() != CV_8UC3 || outimg.type() != CV_8UC1)
26 LFATAL(
"Need RGB byte input and gray byte output images of same dims");
31 case superpixel::Algo::SLIC:
32 case superpixel::Algo::SLICO:
34 auto sp = cv::ximgproc::createSuperpixelSLIC(inimg, algo::get() == superpixel::Algo::SLIC ?
35 cv::ximgproc::SLIC : cv::ximgproc::SLICO,
38 sp->iterate(iterations::get());
40 sp->enforceLabelConnectivity(25);
42 cv::Mat res; sp->getLabels(res);
45 switch (output::get())
47 case superpixel::OutType::Labels:
49 if (sp->getNumberOfSuperpixels() > 255)
LERROR(
"More than 255 superpixels, graylevel confusion will occur");
51 int const * src =
reinterpret_cast<int const *
>(res.data);
52 unsigned char * dst =
reinterpret_cast<unsigned char *
>(outimg.data);
53 int const siz = inimg.rows * inimg.cols;
55 for (
int i = 0; i < siz; ++i) *dst++ = *src++;
59 case superpixel::OutType::Contours:
61 cv::cvtColor(inimg, outimg, cv::COLOR_RGB2GRAY);
63 cv::Mat mask; sp->getLabelContourMask(mask,
false);
67 char const * s =
reinterpret_cast<char const *
>(mask.data);
68 unsigned char * d = outimg.data;
int sz = mask.total();
69 for (
int i = 0; i < sz; ++i) {
if (*s < 0) *d = 255; ++s; ++d; }
76 case superpixel::Algo::SEEDS:
78 auto sp = cv::ximgproc::createSuperpixelSEEDS(inimg.cols, inimg.rows, inimg.channels(), numpix::get(),
81 sp->iterate(inimg, iterations::get());
83 cv::Mat res; sp->getLabels(res);
86 switch (output::get())
88 case superpixel::OutType::Labels:
90 if (sp->getNumberOfSuperpixels() > 255)
LERROR(
"More than 255 superpixels, graylevel confusion will occur");
92 int const * src =
reinterpret_cast<int const *
>(res.data);
93 unsigned char * dst =
reinterpret_cast<unsigned char *
>(outimg.data);
94 int const siz = inimg.rows * inimg.cols;
96 for (
int i = 0; i < siz; ++i) *dst++ = *src++;
100 case superpixel::OutType::Contours:
102 cv::cvtColor(inimg, outimg, cv::COLOR_RGB2GRAY);
104 cv::Mat mask; sp->getLabelContourMask(mask,
false);
108 char const * s =
reinterpret_cast<char const *
>(mask.data);
109 unsigned char * d = outimg.data;
int sz = mask.total();
110 for (
int i = 0; i < sz; ++i) {
if (*s < 0) *d = 255; ++s; ++d; }