Example #1
0
  void RGBDImage :: fillRgbFromUserLabels(cv::Mat3b& img) const
  {
    if (!m_user_labels.data)
      return;

    const Vec3b colors[] = {
      Vec3b(255,0,0),
      Vec3b(255,255,0),
      Vec3b(255,0,255),
      Vec3b(255,255,255),
      Vec3b(0,255,0),
      Vec3b(0,255,255),
      Vec3b(0,0,255),
    };
    int nb_colors = sizeof(colors) / sizeof(Vec3b);

    img.create(m_user_labels.size());
    for_all_rc(m_user_labels)
    {
      int label = m_user_labels(r,c);
      if (label == 0)
        img(r,c) = Vec3b(0,0,0);
      else
        img(r,c) = colors[label%nb_colors];
    }
  }
Example #2
0
void HSColorModel :: show(cv::Mat3b& hist_img) const
{
  ntk_assert(m_histogram.data, "Model was not build.");
  ntk_assert(m_histogram.dims == 2, "This is for 2d histograms");

  int scale = 10;
  int x_bins = m_histogram.size[0];
  int y_bins = m_histogram.size[1];

  double min_value = 0, max_value = 0;
  minMaxLoc(m_histogram, &min_value, &max_value, 0, 0 );

  hist_img.create(x_bins*scale,y_bins*scale);
  hist_img = Vec3b(0,0,0);

  for(int h = 0; h < x_bins; h++ )
  {
    for(int s = 0; s < y_bins; s++ )
    {
      float bin_val = m_histogram(h,s);
      int intensity = cvRound(bin_val*255.0/max_value);
      rectangle(hist_img,
                Point( h*scale, s*scale ),
                Point( (h+1)*scale - 1, (s+1)*scale - 1),
                CV_RGB(intensity,intensity,intensity),
                CV_FILLED );
    }
  }
}