コード例 #1
0
void PlotData(const char *title, const char *xaxis, const char *yaxis,
	double xmin, double xmax, std::vector<double> &values)
{
	CImg<double> y(values.data(), values.size());

	const unsigned int plot_type = 1;
	const unsigned int vertex_type = 0;

	if (y.is_empty()) return;

	CImgDisplay disp;
	disp.assign(cimg_fitscreen(640,480,1),0,0).set_title(title);
	show_graph(disp, y, plot_type, vertex_type, xaxis, xmin, xmax, yaxis);
}
コード例 #2
0
void Scope2(const char *title, std::vector<double> &values)
{
	CImg<double> y(values.data(), values.size());

	float x0 =    0.0f;
	float x1 =  1.25f * values.size();
	const unsigned int plot_type = 1;
	const unsigned int vertex_type = 0;

	if (y.is_empty()) return;

	CImgDisplay disp;
	disp.assign(cimg_fitscreen(640,480,1),0,0).set_title(title);
	show_graph(disp, y, plot_type, vertex_type, "t / ns", x0, x1, "adc units");

//	y.display_graph(title ,plot_type, vertex_type, "t / ns", x0,x1, "adc units");
}
コード例 #3
0
void show_graph2(CImgDisplay &disp, CImg<double> &data,
	const unsigned int plot_type, const unsigned int vertex_type,
	const char *const labelx, const double xmin, const double xmax,
	const char *const labely, const double ymin, const double ymax)
{
	if (data.is_empty()) return;

	if (!disp) disp.assign(cimg_fitscreen(640,480,1),0,0).set_title("CImg<%s>", data.pixel_type());

	const unsigned long siz = (unsigned long)data._width*data._height*data._depth, siz1 = cimg::max(1U,siz-1);
	disp.normalization();

	disp.show().flush()._normalization = 0;

	double y0 = ymin, y1 = ymax, nxmin = xmin, nxmax = xmax;
	if (nxmin==nxmax) { nxmin = 0; nxmax = siz1; }
	int x0 = 0, x1 = data.width()*data.height()*data.depth() - 1;




	x0 = 0; x1 = data.width()*data.height()*data.depth()-1; y0 = ymin; y1 = ymax;

	CImg<double> zoom(x1-x0+1,1,1,data.spectrum());
	cimg_forC(data,c) zoom.get_shared_channel(c) = CImg<double>(data.data(x0,0,0,c),x1-x0+1,1,1,1,true);

	if (y0==y1) { y0 = zoom.min_max(y1); const double dy = y1 - y0; y0-=dy/20; y1+=dy/20; }
	if (y0==y1) { --y0; ++y1; }
	const CImg<int> selection = zoom.get_select_graph(disp,plot_type,vertex_type,
                                                       labelx,
                                                       nxmin + x0*(nxmax-nxmin)/siz1,
                                                       nxmin + x1*(nxmax-nxmin)/siz1,
                                                       labely,y0,y1);

	while (!disp.key() && !disp.is_closed())
	{
	    disp.wait();
	}

}
コード例 #4
0
int main(int argc,char **argv)
{
  cimg_usage("Search Path");
  
  const char* file_i  = cimg_option("-i","input.bmp","Input image");
  const int blur      = cimg_option("-blur",2,"CImg blur value");
  //   float sigma         = cimg_option("-s", 1.0,"Sigma");
  
  CImg<unsigned char> image_in(file_i);
  CImg<unsigned char> image_gray = image_in.get_resize(-100,-100,-100,1); 
  CImg<unsigned char> image_rgb  = image_in.get_resize(-100,-100,-100,3); 
  
  CImg<unsigned char> blur_img = image_gray.get_blur(blur);
  //   CImg<unsigned char> blur_img(image);
  //   blur_img.fill(0);
  //   PGaussianFiltering2D(image, blur_img, sigma);
  CImg<unsigned char> gradient = gradient_cimg(blur_img, 2);
  CImg<unsigned char> gradient_norm = gradient.get_normalize(10,255);
  CImg<unsigned char> gradient_colr = gradient_cimg( image_rgb.get_blur(blur) , 2);
  
  int Dx = image_in.width();
  int Dy = image_in.height();
  CImg<unsigned char> canvas(image_rgb);
  CImg<unsigned char> gcanvas(gradient_colr);
  CImg<unsigned char> marker(Dx,Dy,1,1,0);
  CImg<unsigned char> marker_neg(Dx,Dy,1,1,0);
  CImg<unsigned char> gradmarker(Dx,Dy,1,1,0);
  
  CImg<signed int>    result(Dx,Dy,1,1,-1);
  CImg<unsigned char> result_ok0(Dx,Dy,1,1,0);
  CImg<unsigned char> result_ok1(Dx,Dy,1,3,0);
  CImg<unsigned char> result_ok2(Dx,Dy,1,1,0);
  
  CImgDisplay disp_canvas( cimg_fitscreen(canvas.width(),canvas.height(),canvas.depth()),  "Usage: L,R mouse, F1,F2,c" );
  CImgDisplay disp_result( cimg_fitscreen(canvas.width(),canvas.height(),canvas.depth()),  "Result" );
  CImgDisplay disp_gcanvas( cimg_fitscreen(canvas.width(),canvas.height(),canvas.depth()), "Gradient" );
  
  canvas.display(disp_canvas);
  gcanvas.display(disp_gcanvas);
  result_ok0.display(disp_result);
  
  CImg<unsigned char> marker_disp(disp_canvas.width(), disp_canvas.height(), 1, 3, 0);
  int circle_size1a = 3;
  int circle_size1b = (float) Dx / (float)disp_canvas.width() * circle_size1a + 0.5f;
  int circle_size2a = 5;
  int circle_size2b = (float) Dx / (float)disp_canvas.width() * circle_size2a + 0.5f;
  
  randomColorForLabels();
  
  int draw_type=1;
  bool clicked=false;
  volatile unsigned int btt=0;
  int mx=0, my=0, px=0, py=0, mouse_x=0, mouse_y=0, prev_x=0, prev_y=0;
  while (!disp_canvas.is_closed()) {
    disp_canvas.wait();
    
    if (disp_canvas.key()) {
      switch (disp_canvas.key()) {
        case cimg::keyF1:  draw_type=1; break;
        case cimg::keyF2:  draw_type=2; break;
        case cimg::keyC:
          marker.fill(0); marker_disp.fill(0);
          canvas.assign(image_rgb).display(disp_canvas);
          gcanvas.assign(gradient_colr).display(disp_gcanvas);
          break;
      }
      disp_canvas.set_key();
    }
    
    if (disp_canvas.mouse_x()>=0 && disp_canvas.mouse_y()>=0) {
      
      mx = disp_canvas.mouse_x(), 
      my = disp_canvas.mouse_y();
      mouse_x = mx*Dx/disp_canvas.width();
      mouse_y = my*Dy/disp_canvas.height();
      
      btt = disp_canvas.button();
      
      if (btt == 1) {
        if (draw_type==1) {
          marker.draw_line(mouse_x,mouse_y,prev_x,prev_y,white);
          marker_disp.draw_line(mx,my,px,py,red);
        }
        else {
          marker.draw_circle(mouse_x,mouse_y,circle_size1b,white);
          marker_disp.draw_circle(mx,my,circle_size1a,red);
        }
        draw_results(canvas,marker,red);  //canvas = canvas | marker;
        draw_results(gcanvas,marker,red); //gcanvas = gcanvas | marker;
        clicked=true;
      } else
        if (btt == 2) {
          marker.draw_circle(mouse_x,mouse_y,circle_size2b,black);
          marker_disp.draw_circle(mx,my,circle_size2a,white);
          canvas.assign(image_rgb); //.resize(disp_canvas);
          draw_results(canvas,marker,red);
          draw_results(canvas,result_ok2,yellow);
          gcanvas.assign(gradient_colr); //.resize(disp_gcanvas);
          draw_results(gcanvas,marker,red);
          draw_results(gcanvas,result_ok2,yellow);
          clicked=true;
        } else
          if (clicked) {
            cimg_forXY(marker,x,y) marker_neg(x,y) = 255-marker(x,y); // Invert marker images (lines should to be black)
            gradmarker = gradient_norm & marker_neg;                  // Add marker image to gradient image
            
            result.fill(-1);
            WatershedSegmentation(gradmarker, &result, 1, 0);         // Run marker-based watershed algorithm
            
            //result_ok0 = result.equalize(256,0,255);
            result_ok1 = colorizeLabelImage( result );
            result_ok2 = gradient_cimg(result,2);                     // Boundary detection
            cimg_forXY(result_ok2,x,y) result_ok2(x,y) = result_ok2(x,y)>0?255:0;
            canvas.assign(image_rgb); //.resize(disp_canvas);
            draw_results(canvas,marker,red);
            draw_results(canvas,result_ok2,yellow);
            gcanvas.assign(gradient_colr); //.resize(disp_gcanvas);
            draw_results(gcanvas,marker,red);
            draw_results(gcanvas,result_ok2,yellow);
            clicked=false;
          }
          
          prev_x = mouse_x; prev_y = mouse_y;
          px = mx; py = my;
          
          canvas.display(disp_canvas);
          gcanvas.display(disp_gcanvas);
          result_ok1.display(disp_result);
    }
  }

  return 0;
}
コード例 #5
0
void show_graph(CImgDisplay &disp, CImg<double> &data,
	const unsigned int plot_type, const unsigned int vertex_type,
	const char *const labelx, const double xmin, const double xmax,
	const char *const labely, const double ymin, const double ymax)
{
  if (data.is_empty()) return;

  if (!disp) disp.assign(cimg_fitscreen(640,480,1),0,0).set_title("CImg<%s>", data.pixel_type());

  const unsigned long siz = (unsigned long)data._width*data._height*data._depth, siz1 = cimg::max(1U,siz-1);
  const unsigned int old_normalization = disp.normalization();

  disp.show().flush()._normalization = 0;

  double y0 = ymin, y1 = ymax, nxmin = xmin, nxmax = xmax;
  if (nxmin==nxmax) { nxmin = 0; nxmax = siz1; }
  int x0 = 0, x1 = data.width()*data.height()*data.depth() - 1, key = 0;

  for (bool reset_view = true, resize_disp = false; !key && !disp.is_closed(); )
  {
    if (reset_view) { x0 = 0; x1 = data.width()*data.height()*data.depth()-1; y0 = ymin; y1 = ymax; reset_view = false; }

    CImg<double> zoom(x1-x0+1,1,1,data.spectrum());
    cimg_forC(data,c) zoom.get_shared_channel(c) = CImg<double>(data.data(x0,0,0,c),x1-x0+1,1,1,1,true);

    if (y0==y1) { y0 = zoom.min_max(y1); const double dy = y1 - y0; y0-=dy/20; y1+=dy/20; }
    if (y0==y1) { --y0; ++y1; }
    const CImg<int> selection = zoom.get_select_graph(disp,plot_type,vertex_type,
                                                       labelx,
                                                       nxmin + x0*(nxmax-nxmin)/siz1,
                                                       nxmin + x1*(nxmax-nxmin)/siz1,
                                                       labely,y0,y1);

    const int mouse_x = disp.mouse_x(), mouse_y = disp.mouse_y();
    if (selection[0]>=0)
	{
      if (selection[2]<0) reset_view = true;
      else
	  {
        x1 = x0 + selection[2]; x0+=selection[0];
        if (selection[1]>=0 && selection[3]>=0)
		{
          y0 = y1 - selection[3]*(y1-y0)/(disp.height()-32);
          y1-=selection[1]*(y1-y0)/(disp.height()-32);
        }
      }
    }
	else
	{
      bool go_in = false, go_out = false, go_left = false, go_right = false, go_up = false, go_down = false;

      switch (key = disp.key())
	  {
      case cimg::keyHOME : reset_view = resize_disp = true; key = 0; disp.set_key(); break;
      case cimg::keyPADADD : go_in = true; go_out = false; key = 0; disp.set_key(); break;
      case cimg::keyPADSUB : go_out = true; go_in = false; key = 0; disp.set_key(); break;
      case cimg::keyARROWLEFT : case cimg::keyPAD4 : go_left = true; go_right = false; key = 0; disp.set_key(); break;
      case cimg::keyARROWRIGHT : case cimg::keyPAD6 : go_right = true; go_left = false; key = 0; disp.set_key(); break;
      case cimg::keyARROWUP : case cimg::keyPAD8 : go_up = true; go_down = false; key = 0; disp.set_key(); break;
      case cimg::keyARROWDOWN : case cimg::keyPAD2 : go_down = true; go_up = false; key = 0; disp.set_key(); break;
      case cimg::keyPAD7 : go_left = true; go_up = true; key = 0; disp.set_key(); break;
      case cimg::keyPAD9 : go_right = true; go_up = true; key = 0; disp.set_key(); break;
      case cimg::keyPAD1 : go_left = true; go_down = true; key = 0; disp.set_key(); break;
      case cimg::keyPAD3 : go_right = true; go_down = true; key = 0; disp.set_key(); break;
      }

	  if (disp.wheel())
	  {
        if (disp.is_keyCTRLLEFT() || disp.is_keyCTRLRIGHT()) go_out = !(go_in = disp.wheel()>0);
        else if (disp.is_keySHIFTLEFT() || disp.is_keySHIFTRIGHT()) go_left = !(go_right = disp.wheel()>0);
        else go_up = !(go_down = disp.wheel()<0);
        key = 0;
      }

      if (go_in)
	  {
        const int
          xsiz = x1 - x0,
          mx = (mouse_x-16)*xsiz/(disp.width()-32),
          cx = x0 + (mx<0?0:(mx>=xsiz?xsiz:mx));
        if (x1-x0>4)
		{
          x0 = cx - 7*(cx-x0)/8; x1 = cx + 7*(x1-cx)/8;
          if (disp.is_keyCTRLLEFT() || disp.is_keyCTRLRIGHT())
		  {
            const double
              ysiz = y1 - y0,
              my = (mouse_y-16)*ysiz/(disp.height()-32),
              cy = y1 - (my<0?0:(my>=ysiz?ysiz:my));
              y0 = cy - 7*(cy-y0)/8; y1 = cy + 7*(y1-cy)/8;
          } else y0 = y1 = 0;
        }
      }

	  if (go_out)
	  {
        if (x0>0 || x1<(int)siz1)
		{
          const int delta_x = (x1-x0)/8, ndelta_x = delta_x?delta_x:(siz>1?1:0);
          const double ndelta_y = (y1-y0)/8;
          x0-=ndelta_x; x1+=ndelta_x;
          y0-=ndelta_y; y1+=ndelta_y;
          if (x0<0) { x1-=x0; x0 = 0; if (x1>=(int)siz) x1 = (int)siz1; }
          if (x1>=(int)siz) { x0-=(x1-siz1); x1 = (int)siz1; if (x0<0) x0 = 0; }
        }
      }

	  if (go_left)
	  {
        const int delta = (x1-x0)/5, ndelta = delta?delta:1;
        if (x0-ndelta>=0) { x0-=ndelta; x1-=ndelta; }
        else { x1-=x0; x0 = 0; }
        go_left = false;
      }

	  if (go_right)
	  {
        const int delta = (x1-x0)/5, ndelta = delta?delta:1;
        if (x1+ndelta<(int)siz) { x0+=ndelta; x1+=ndelta; }
        else { x0+=(siz1-x1); x1 = siz1; }
        go_right = false;
      }

	  if (go_up)
	  {
        const double delta = (y1-y0)/10, ndelta = delta?delta:1;
        y0+=ndelta; y1+=ndelta;
        go_up = false;
      }

      if (go_down)
	  {
        const double delta = (y1-y0)/10, ndelta = delta?delta:1;
        y0-=ndelta; y1-=ndelta;
        go_down = false;
      }
    }
  }
  disp._normalization = old_normalization;
}