src/Foundation/Media/Gimela.Media.Imaging/Blob/BlobCounterBase.cs
/// <summary>
/// Get list of object's edge points.
/// </summary>
/// 
/// <param name="blob">Blob to collect edge points for.</param>
/// 
/// <returns>Returns unsorted list of blob's edge points.</returns>
/// 
/// <remarks><para>The method scans each row and column of the blob and finds the
/// most top/bottom/left/right points. The method returns similar result as if results of
/// both <see cref="GetBlobsLeftAndRightEdges"/> and <see cref="GetBlobsTopAndBottomEdges"/>
/// methods were combined, but each edge point occurs only once in the list.</para>
/// 
/// <para><note>Edge points in the returned list are not ordered. This makes the list unusable
/// for visualization with methods, which draw polygon or poly-line. But the returned list
/// can be used with such algorithms, like convex hull search, shape analyzer, etc.</note></para>
/// </remarks>
/// 
/// <exception cref="ApplicationException">No image was processed before, so blob
/// can not be extracted.</exception>
/// 
Get list of object's edge points.
Get list of object ' s edge points .
public List<IntPoint> GetBlobsEdgePoints(Blob blob)
    {
      if (objectLabels == null)
        throw new ApplicationException("Image should be processed before to collect objects map.");
      List<IntPoint> edgePoints = 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;
      int[] leftProcessedPoints = new int[blob.Rectangle.Height];
      int[] rightProcessedPoints = new int[blob.Rectangle.Height];
      for (int y = ymin; y <= ymax; y++)
      {
        int p = y * imageWidth + xmin;
        for (int x = xmin; x <= xmax; x++, p++)
        {
          if (objectLabels[p] == label)
          {
            edgePoints.Add(new IntPoint(x, y));
            leftProcessedPoints[y - ymin] = x;
            break;
          }
        }
        p = y * imageWidth + xmax;
        for (int x = xmax; x >= xmin; x--, p--)
        {
          if (objectLabels[p] == label)
          {
            if (leftProcessedPoints[y - ymin] != x)
            {
              edgePoints.Add(new IntPoint(x, y));
            }
            rightProcessedPoints[y - ymin] = x;
            break;
          }
        }
      }
      for (int x = xmin; x <= xmax; x++)
      {
        int p = ymin * imageWidth + x;
        for (int y = ymin, y0 = 0; y <= ymax; y++, y0++, p += imageWidth)
        {
          if (objectLabels[p] == label)
          {
            if ((leftProcessedPoints[y0] != x) &&
                 (rightProcessedPoints[y0] != x))
            {
              edgePoints.Add(new IntPoint(x, y));
            }
            break;
          }
        }
        p = ymax * imageWidth + x;
        for (int y = ymax, y0 = ymax - ymin; y >= ymin; y--, y0--, p -= imageWidth)
        {
          if (objectLabels[p] == label)
          {
            if ((leftProcessedPoints[y0] != x) &&
                 (rightProcessedPoints[y0] != x))
            {
              edgePoints.Add(new IntPoint(x, y));
            }
            break;
          }
        }
      }
      return edgePoints;
    }
public List < IntPoint > GetBlobsEdgePoints ( Blob blob ) { if ( objectLabels == null ) throw new ApplicationException ( " " ) ; List < IntPoint > edgePoints = 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 ; int [ ] leftProcessedPoints = new int [ blob . Rectangle . Height ] ; int [ ] rightProcessedPoints = new int [ blob . Rectangle . Height ] ; for ( int y = ymin ; y <= ymax ; y ++ ) { int p = y * imageWidth + xmin ; for ( int x = xmin ; x <= xmax ; x ++ , p ++ ) { if ( objectLabels [ p ] == label ) { edgePoints . Add ( new IntPoint ( x , y ) ) ; leftProcessedPoints [ y - ymin ] = x ; break ; } } p = y * imageWidth + xmax ; for ( int x = xmax ; x >= xmin ; x -- , p -- ) { if ( objectLabels [ p ] == label ) { if ( leftProcessedPoints [ y - ymin ] != x ) { edgePoints . Add ( new IntPoint ( x , y ) ) ; } rightProcessedPoints [ y - ymin ] = x ; break ; } } } for ( int x = xmin ; x <= xmax ; x ++ ) { int p = ymin * imageWidth + x ; for ( int y = ymin , y0 = 0 ; y <= ymax ; y ++ , y0 ++ , p += imageWidth ) { if ( objectLabels [ p ] == label ) { if ( ( leftProcessedPoints [ y0 ] != x ) && ( rightProcessedPoints [ y0 ] != x ) ) { edgePoints . Add ( new IntPoint ( x , y ) ) ; } break ; } } p = ymax * imageWidth + x ; for ( int y = ymax , y0 = ymax - ymin ; y >= ymin ; y -- , y0 -- , p -= imageWidth ) { if ( objectLabels [ p ] == label ) { if ( ( leftProcessedPoints [ y0 ] != x ) && ( rightProcessedPoints [ y0 ] != x ) ) { edgePoints . Add ( new IntPoint ( x , y ) ) ; } break ; } } } return edgePoints ; }
Get list of object's edge points.
Get list of object ' s edge points .
// check if objects map was collected // array of already processed points on left/right edges // (index in these arrays represent Y coordinate, but value - X coordinate) // for each line // scan from left to right // scan from right to left // avoid adding the point we already have // for each column // scan from top to bottom // avoid adding the point we already have // scan from bottom to top // avoid adding the point we already have
Returns unsorted list of blob's edge points.
Returns unsorted list of blob ' s edge points .
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 .
remarks
The method scans each row and column of the blob and finds the
most top/bottom/left/right points. The method returns similar result as if results of
both

and
methods were combined, but each edge point occurs only once in the list.Edge points in the returned list are not ordered. This makes the list unusable
for visualization with methods, which draw polygon or poly-line. But the returned list
can be used with such algorithms, like convex hull search, shape analyzer, etc.
The method scans each row and column of the blob and finds the most top / bottom / left / right points . The method returns similar result as if results of both and methods were combined but each edge point occurs only once in the list . Edge points in the returned list are not ordered . This makes the list unusable for visualization with methods which draw polygon or poly - line . But the returned list can be used with such algorithms like convex hull search shape analyzer etc .