Пример #1
0
Z2i::DigitalSet* newDigitalSet2DFromBinaryImage( const GrayImage &image ) {
	Z2i::DigitalSet * objpts = new Z2i::DigitalSet( image.domain() ) ;
	for ( Z2i::Domain::ConstIterator pt = image.domain().begin() ; pt != image.domain().end() ; pt++ )
	{
		if ( image( *pt ) == (unsigned char) 255 && 
					(*pt).at(0) > 96 && (*pt).at(0) < 390  /** 3 * image.domain().upperBound().at(0)*/ &&
					(*pt).at(1) > 112 && (*pt).at(1) < 416  /** 3 * image.domain().upperBound().at(1)*/ )
			objpts->insertNew( *pt ) ;
	}
	return objpts ;
}
Пример #2
0
void process_slice( const boost::filesystem::path &folderPath, uint z, Z3i::DigitalSet &set3d ) {
	boost::filesystem::path filePath = folderPath ;
	filePath /= QString("slice-%1.pgm").arg( z, 0, 10 ).toStdString() ;
	
	GrayImage image = PNMReader<GrayImage>::importPGM( filePath.string() );
	
	Z2i::DigitalSet *objpts = newDigitalSet2DFromBinaryImage( image ) ;
	if ( !objpts->empty() ) {
		VertexPolygon convexhull ;
		Z2i::Object4_8 obj( Z2i::dt4_8, *objpts) ;
		Z2i::Object4_8 boundary = obj.border() ;
		if ( boundary.size() <= 3 )
		{
			trace.info()<<"Warning : boundary is ";
			for ( Z2i::DigitalSet::ConstIterator pt = boundary.pointSet().begin() ; pt != boundary.pointSet().end() ; pt++ )
				trace.info()<<(*pt)<<" " ;
			trace.info()<<std::endl;
		}
		Geom2D::ConvexHull( boundary.pointSet(), convexhull ) ;
		EdgePolygon segs ;
		init_edges_polygon( segs, convexhull ) ;
		uint new3Dpts = 0 ;
		if ( segs.size() >= 3 )
			for ( Z2i::Domain::ConstIterator pt = image.domain().begin() ; pt != image.domain().end() ; pt++ )
			{
				if ( image( *pt ) == (unsigned char) 255 ) continue ;
				bool bInside = true ;
				for ( uint iSeg = 0 ; iSeg != segs.size() && bInside; iSeg++ )
					if ( segs[iSeg].signedDistance( *pt ) < 0 ) bInside = false ;
				if ( !bInside ) continue ;
				set3d.insertNew( Z3i::Point( (*pt).at(0),(*pt).at(1), z ) ) ;
				new3Dpts++ ;
			}
		Z2i::Point UL, BR ;
		boundary.pointSet().computeBoundingBox( UL, BR ) ;
		std::cerr<<QString( "Slice %1").arg( z,10,10,QLatin1Char('0')).toStdString() ;
		std::cerr<<setw(6)<<objpts->size()<<" "
					<<setw(6)<<boundary.size()<<" "
					<<setw(6)<<new3Dpts<<" "
					<<setw(4)<<UL.at(0)<<","
					<<setw(4)<<UL.at(1)<<" - "
					<<setw(4)<<BR.at(0)<<","
					<<setw(4)<<BR.at(1)<<std::endl;
	}
	delete objpts ;
}
Пример #3
0
bool testSetFromImage()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;
  
  trace.beginBlock ( "Testing SetFromImage ..." );
  
  Point a(0,0);
  Point b(23,43);
  Point c(12,12);

  typedef ImageContainerBySTLVector<Domain,int> Image;
  Image image(a,b);
  image.setValue(c,128);
  
  DigitalSet aSet(Domain(a,b));
  
  //test of the append method
  SetFromImage<DigitalSet>::append<Image>(aSet, image, 0,255);

  trace.info()<< "DigitalSet:= ";
  for(DigitalSet::ConstIterator it= aSet.begin(),itend=aSet.end();
      it != itend;
      ++it)
    trace.info() << *it<< " ";
  trace.info()<<endl;

  nbok += (aSet.find(c) != aSet.end() ) ? 1 : 0; 
  nb++;



  trace.beginBlock ( "Testing SetFromImage using pgm test file ..." );
  
  std::string filename = testPath + "samples/circleR10modif.pgm";
  Image image2 = PNMReader<Image>::importPGMImage( filename ); 
  Z2i::DigitalSet setFromImg (image2.domain());
  SetFromImage<Z2i::DigitalSet>::append<Image>(setFromImg, image2, 0, 255);

  
  for( Z2i::DigitalSet::Iterator it= setFromImg.begin(); 
       it!=setFromImg.end(); it++){
    trace.info()<< *it << endl;
  }
  trace.info()<< "Size=" << setFromImg.size();
  
  Image setImage = ImageFromSet<Image>::create(setFromImg, 1,
					       false, 
 					       setFromImg.begin(), 
 					       setFromImg.end());
  
  trace.info() << "Image at 0,12:" << setImage(Point(0,12))<< endl;
  trace.info() << "(" << nbok << "/" << nb << ") "
	       << "true == true" << std::endl;
  trace.endBlock();
  
  return nbok == nb;
}
Пример #4
0
Z3i::Domain scene_dimensions( const boost::filesystem::path &folderPath ) {
	uint depth = 0 ;
	boost::filesystem::path filePath;
	do {
		filePath = folderPath ;
		filePath /= QString("slice-%1.pgm").arg( depth, 0, 10 ).toStdString() ;
		depth++ ;
	} while ( boost::filesystem::exists( filePath ) ) ;
	depth-- ;
	if ( depth == 0 ) return Z3i::Domain( Z3i::Point(0,0,0), Z3i::Point(0,0,0) ) ;
	filePath = folderPath ;
	filePath /= QString("slice-%1.pgm").arg( depth/2, 0, 10 ).toStdString() ; /** "slice-0.pgm" ;*/
	GrayImage image = PNMReader<GrayImage>::importPGM( filePath.string() );
	#if 0
	Z2i::DigitalSet *pts = newDigitalSet2DFromBinaryImage( image ) ;
	Board2D board ;
	board << image.domain()<<*pts ;
	board.saveSVG( "cropcheck.svg");
	trace.info()<<"Get "<<pts->size()<<" points on slide "<<filePath.string()<<std::endl;
	delete pts ;
	#endif
	
	return Z3i::Domain( Z3i::Point(0,0,0), Z3i::Point( image.domain().upperBound().at(0),image.domain().upperBound().at(1),depth) ) ;
}