31 #include "vpTutoSegmentation.h"
33 #include <visp3/core/vpGaussRand.h>
35 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 #ifdef ENABLE_VISP_NAMESPACE
43 void performSegmentationHSV(vpTutoCommonData &data)
45 const unsigned int height = data.m_I_orig.getHeight(), width = data.m_I_orig.getWidth();
53 data.m_I_orig.getSize());
60 data.m_mask.getSize());
65 std::vector< VISP_NAMESPACE_ADDRESSING vpImagePoint > extractSkeleton(vpTutoCommonData &data)
67 const int height = data.m_mask.getHeight();
68 const int width = data.m_mask.getWidth();
69 data.m_Iskeleton.resize(height, width, 0);
70 std::vector<vpImagePoint> points;
72 for (
int y = 0; y < height; ++y) {
74 for (
int x = 0; x < width - 1; ++x) {
75 if ((data.m_mask[y][x] > 0) && (data.m_mask[y][x + 1] > 0)) {
80 else if (data.m_mask[y][x] > 0) {
84 cx =
static_cast<int>(((left + x) - 1) * 0.5f);
88 data.m_Iskeleton[y][cx] = 255;
95 for (
int x = 0; x < width; ++x) {
97 for (
int y = 0; y < height - 1; ++y) {
98 if ((data.m_mask[y][x] > 0) && (data.m_mask[y + 1][x] > 0)) {
103 else if (data.m_mask[y][x] > 0) {
106 cy =
static_cast<int>(((top + y) - 1) * 0.5f);
108 if (data.m_Iskeleton[cy][x] == 0) {
110 points.push_back(pt);
111 data.m_Iskeleton[cy][x] = 255;
120 std::vector< vpImagePoint > addSaltAndPepperNoise(
const std::vector< vpImagePoint > &noisefreePts, vpTutoCommonData &data)
122 const unsigned int nbNoiseFreePts =
static_cast<unsigned int>(noisefreePts.size());
123 const unsigned int nbPtsToAdd =
static_cast<unsigned int>(data.m_ratioSaltPepperNoise * nbNoiseFreePts);
124 const double width = data.m_Iskeleton.getWidth();
125 const double height = data.m_Iskeleton.getHeight();
126 data.m_IskeletonNoisy = data.m_Iskeleton;
129 std::vector<vpImagePoint> noisyPts = noisefreePts;
130 for (
unsigned int i = 0; i < nbPtsToAdd + 1; ++i) {
131 double uNormalized = rngX();
132 double vNormalized = rngY();
134 uNormalized = std::max(uNormalized, 0.);
135 uNormalized = std::min(uNormalized, 0.99999);
136 vNormalized = std::max(vNormalized, 0.);
137 vNormalized = std::min(vNormalized, 0.99999);
139 double u = uNormalized * width;
140 double v = vNormalized * height;
143 noisyPts.push_back(pt);
144 data.m_IskeletonNoisy[
static_cast<int>(v)][
static_cast<int>(u)] = 255;
151 void dummy_vpTutoSegmentation() { }
Class for generating random number with normal probability density.
static void RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, unsigned int size)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
VISP_EXPORT double measureTimeMicros()