Beispiel #1
0
/*
- FUNCTION: PrintBlobs
- FUNCTIONALITY: Prints some blob features in an ASCII file
- PARAMETERS:
- nom_fitxer: full path + filename to generate
- RESULT:
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
void CBlobResult::PrintBlobs( char *nom_fitxer ) const
{
  double_stl_vector area, /*perimetre,*/ exterior, mitjana, compacitat, longitud, 
    externPerimeter, perimetreConvex, perimetre;
  int i;
  FILE *fitxer_sortida;

  area      = GetSTLResult( CBlobGetArea());
  perimetre = GetSTLResult( CBlobGetPerimeter());
  exterior  = GetSTLResult( CBlobGetExterior());
  mitjana   = GetSTLResult( CBlobGetMean());
  compacitat = GetSTLResult(CBlobGetCompactness());
  longitud  = GetSTLResult( CBlobGetLength());
  externPerimeter = GetSTLResult( CBlobGetExternPerimeter());
  perimetreConvex = GetSTLResult( CBlobGetHullPerimeter());

  fitxer_sortida = fopen( nom_fitxer, "w" );

  for(i=0; i<GetNumBlobs(); i++)
  {
    fprintf( fitxer_sortida, "blob %d ->\t a=%7.0f\t p=%8.2f (%8.2f extern)\t pconvex=%8.2f\t ext=%.0f\t m=%7.2f\t c=%3.2f\t l=%8.2f\n",
      i, area[i], perimetre[i], externPerimeter[i], perimetreConvex[i], exterior[i], mitjana[i], compacitat[i], longitud[i] );
  }
  fclose( fitxer_sortida );

}
/*
- FUNCTION: GetNthBlob
- FUNCTIONALITY: Gets the n-th blob ordering first the blobs with some criteria
- PARAMETERS:
    - criteri: criteria to order the blob array
    - nBlob: index of the returned blob in the ordered blob array
    - dst: where to store the result
- RESULT:
- RESTRICTIONS:
- AUTHOR: Ricard Borr�s
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
void CBlobResult::GetNthBlob( funcio_calculBlob* criteri, int nBlob, CBlob& dst ) const
{
    // verifiquem que no estem accedint fora el vector de blobs
    if ( nBlob < 0 || nBlob >= GetNumBlobs() )
    {
        //RaiseError( EXCEPTION_BLOB_OUT_OF_BOUNDS );
        dst = CBlob();
        return;
    }

    double_stl_vector avaluacioBlobs, avaluacioBlobsOrdenat;
    double valorEnessim;

    //avaluem els blobs amb la funci� pertinent
    avaluacioBlobs = GetSTLResult(criteri);

    avaluacioBlobsOrdenat = double_stl_vector( GetNumBlobs() );

    // obtenim els nBlob primers resultats (en ordre descendent)
    std::partial_sort_copy( avaluacioBlobs.begin(),
                            avaluacioBlobs.end(),
                            avaluacioBlobsOrdenat.begin(),
                            avaluacioBlobsOrdenat.end(),
                            std::greater<double>() );

    valorEnessim = avaluacioBlobsOrdenat[nBlob];

    // busquem el primer blob que t� el valor n-ssim
    double_stl_vector::const_iterator itAvaluacio = avaluacioBlobs.begin();

    bool trobatBlob = false;
    int  indexBlob  = 0;

    while ( itAvaluacio != avaluacioBlobs.end() && !trobatBlob )
    {
        if ( *itAvaluacio == valorEnessim )
        {
            trobatBlob = true;
            dst        = CBlob( GetBlob(indexBlob));
        }

        ++itAvaluacio;
        ++indexBlob;
    }
}
Beispiel #3
0
/**
- FUNCTION: Filter
- FUNCTIONALITY: Get some blobs from the class based on conditions on measures
of the blobs. 
- PARAMETERS:
- dst: where to store the selected blobs
- filterAction:	B_INCLUDE: include the blobs which pass the filter in the result 
B_EXCLUDE: exclude the blobs which pass the filter in the result 
- evaluador: Object to evaluate the blob
- Condition: How to decide if  the result returned by evaluador on each blob
is included or not. It can be:
B_EQUAL,B_NOT_EQUAL,B_GREATER,B_LESS,B_GREATER_OR_EQUAL,
B_LESS_OR_EQUAL,B_INSIDE,B_OUTSIDE
- LowLimit:  numerical value to evaluate the Condition on evaluador(blob)
- HighLimit: numerical value to evaluate the Condition on evaluador(blob).
Only useful for B_INSIDE and B_OUTSIDE
- RESULT:
- It returns on dst the blobs that accomplish (B_INCLUDE) or discards (B_EXCLUDE)
the Condition on the result returned by evaluador on each blob
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
void CBlobResult::Filter(CBlobResult &dst, 
  int filterAction, 
  funcio_calculBlob *evaluador, 
  int condition, 
  double lowLimit, double highLimit /*=0*/)

{
  int i, numBlobs;
  bool resultavaluacio;
  double_stl_vector avaluacioBlobs;
  double_stl_vector::iterator itavaluacioBlobs;

  if( GetNumBlobs() <= 0 ) return;
  if( !evaluador ) return;
  //avaluem els blobs amb la funció pertinent	
  avaluacioBlobs = GetSTLResult(evaluador);
  itavaluacioBlobs = avaluacioBlobs.begin();
  numBlobs = GetNumBlobs();
  switch(condition)
  {
  case B_EQUAL:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs == lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }				
    }
    break;
  case B_NOT_EQUAL:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio = *itavaluacioBlobs != lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_GREATER:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs > lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_LESS:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs < lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_GREATER_OR_EQUAL:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs>= lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_LESS_OR_EQUAL:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs <= lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_INSIDE:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio=( *itavaluacioBlobs >= lowLimit) && ( *itavaluacioBlobs <= highLimit); 
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_OUTSIDE:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio=( *itavaluacioBlobs < lowLimit) || ( *itavaluacioBlobs > highLimit); 
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  }


  // en cas de voler filtrar un CBlobResult i deixar-ho en el mateix CBlobResult
  // ( operacio inline )
  if( &dst == this ) 
  {
    // esborrem els primers blobs ( que són els originals )
    // ja que els tindrem replicats al final si passen el filtre
    blob_vector::iterator itBlobs = m_blobs.begin();
    for( int i = 0; i < numBlobs; i++ )
    {
      delete *itBlobs;
      itBlobs++;
    }
    m_blobs.erase( m_blobs.begin(), itBlobs );
  }
}
Beispiel #4
0
//! Does the Filter method job
void CBlobResult::DoFilter(CBlobResult &dst, int filterAction, funcio_calculBlob *evaluador,
						   int condition, double lowLimit, double highLimit/* = 0*/) const
{
	int i, numBlobs;
	bool resultavaluacio;
	double_stl_vector avaluacioBlobs;
	double_stl_vector::iterator itavaluacioBlobs;

	if( GetNumBlobs() <= 0 ) return;
	if( !evaluador ) return;
	//avaluem els blobs amb la funció pertinent
	avaluacioBlobs = GetSTLResult(evaluador);
	itavaluacioBlobs = avaluacioBlobs.begin();
	numBlobs = GetNumBlobs();
	switch(condition)
	{
		case B_EQUAL:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs == lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_NOT_EQUAL:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio = *itavaluacioBlobs != lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_GREATER:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs > lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_LESS:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs < lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_GREATER_OR_EQUAL:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs>= lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_LESS_OR_EQUAL:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs <= lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_INSIDE:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio=( *itavaluacioBlobs >= lowLimit) && ( *itavaluacioBlobs <= highLimit);
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_OUTSIDE:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio=( *itavaluacioBlobs < lowLimit) || ( *itavaluacioBlobs > highLimit);
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
	}
}