src/Foundation/Media/Gimela.Media.Imaging/Blob/BlobCounterBase.cs
/// <summary>
/// Get list of points on the top and bottom edges of the blob.
/// </summary>
/// 
/// <param name="blob">Blob to collect edge points for.</param>
/// <param name="topEdge">List of points on the top edge of the blob.</param>
/// <param name="bottomEdge">List of points on the bottom edge of the blob.</param>
/// 
/// <remarks><para>The method scans each column of the blob and finds the most top and the
/// most bottom points for it adding them to appropriate lists. The method may be very
/// useful in conjunction with different routines from Geometry,
/// which allow finding convex hull or quadrilateral's corners.</para>
/// 
/// <para><note>Both lists of points are sorted by X coordinate - points with smaller X
/// value go first.</note></para>
/// </remarks>
/// 
/// <exception cref="ApplicationException">No image was processed before, so blob
/// can not be extracted.</exception>
/// 
Get list of points on the top and bottom edges of the blob.
Get list of points on the top and bottom edges of the blob .
public void GetBlobsTopAndBottomEdges(Blob blob, out List<IntPoint> topEdge, out List<IntPoint> bottomEdge)
    {
      if (objectLabels == null)
        throw new ApplicationException("Image should be processed before to collect objects map.");
      topEdge = new List<IntPoint>();
      bottomEdge = new List<IntPoint>();
      int xmin = blob.Rectangle.Left;
      int xmax = xmin + blob.Rectangle.Width - 1;
      int ymin = blob.Rectangle.Top;
      int ymax = ymin + blob.Rectangle.Height - 1;
      int label = blob.ID;
      for (int x = xmin; x <= xmax; x++)
      {
        int p = ymin * imageWidth + x;
        for (int y = ymin; y <= ymax; y++, p += imageWidth)
        {
          if (objectLabels[p] == label)
          {
            topEdge.Add(new IntPoint(x, y));
            break;
          }
        }
        p = ymax * imageWidth + x;
        for (int y = ymax; y >= ymin; y--, p -= imageWidth)
        {
          if (objectLabels[p] == label)
          {
            bottomEdge.Add(new IntPoint(x, y));
            break;
          }
        }
      }
    }
public void GetBlobsTopAndBottomEdges ( Blob blob , out List < IntPoint > topEdge , out List < IntPoint > bottomEdge ) { if ( objectLabels == null ) throw new ApplicationException ( " " ) ; topEdge = new List < IntPoint > ( ) ; bottomEdge = new List < IntPoint > ( ) ; int xmin = blob . Rectangle . Left ; int xmax = xmin + blob . Rectangle . Width - 1 ; int ymin = blob . Rectangle . Top ; int ymax = ymin + blob . Rectangle . Height - 1 ; int label = blob . ID ; for ( int x = xmin ; x <= xmax ; x ++ ) { int p = ymin * imageWidth + x ; for ( int y = ymin ; y <= ymax ; y ++ , p += imageWidth ) { if ( objectLabels [ p ] == label ) { topEdge . Add ( new IntPoint ( x , y ) ) ; break ; } } p = ymax * imageWidth + x ; for ( int y = ymax ; y >= ymin ; y -- , p -= imageWidth ) { if ( objectLabels [ p ] == label ) { bottomEdge . Add ( new IntPoint ( x , y ) ) ; break ; } } } }
Get list of points on the top and bottom edges of the blob.
Get list of points on the top and bottom edges of the blob .
// check if objects map was collected // for each column // scan from top to bottom // scan from bottom to top
No image was processed before, so blob
can not be extracted.
No image was processed before so blob can not be extracted .
blob
Blob
Blob to collect edge points for.
Blob to collect edge points for .
List<IntPoint>
out
topEdge
List of points on the top edge of the blob.
List of points on the top edge of the blob .
bottomEdge
List of points on the bottom edge of the blob.
List of points on the bottom edge of the blob .
remarks
The method scans each column of the blob and finds the most top and the
most bottom points for it adding them to appropriate lists. The method may be very
useful in conjunction with different routines from Geometry,
which allow finding convex hull or quadrilateral's corners.Both lists of points are sorted by X coordinate - points with smaller X
value go first.
The method scans each column of the blob and finds the most top and the most bottom points for it adding them to appropriate lists . The method may be very useful in conjunction with different routines from Geometry which allow finding convex hull or quadrilateral ' s corners . Both lists of points are sorted by X coordinate - points with smaller X value go first .