src/Foundation/Media/Gimela.Media.Imaging/Blob/BlobCounterBase.cs
/// <summary>
/// Build object map from raw image data.
/// </summary>
/// 
/// <param name="image">Source unmanaged binary image data.</param>
/// 
/// <remarks><para>Processes the image and builds objects map, which is used later to extracts blobs.</para></remarks>
/// 
/// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the source image.</exception>
/// <exception cref="InvalidImagePropertiesException">Thrown by some inherited classes if some image property other
/// than the pixel format is not supported. See that class's documentation or the exception message for details.</exception>
/// 
Build object map from raw image data.
Build object map from raw image data .
public void ProcessImage(UnmanagedImage image)
    {
      imageWidth = image.Width;
      imageHeight = image.Height;
      BuildObjectsMap(image);
      CollectObjectsInfo(image);
      if (filterBlobs)
      {
        int[] labelsMap = new int[objectsCount + 1];
        for (int i = 1; i <= objectsCount; i++)
        {
          labelsMap[i] = i;
        }
        int objectsToRemove = 0;
        if (filter == null)
        {
          for (int i = objectsCount - 1; i >= 0; i--)
          {
            int blobWidth = blobs[i].Rectangle.Width;
            int blobHeight = blobs[i].Rectangle.Height;
            if (coupledSizeFiltering == false)
            {
              if (
                  (blobWidth < minWidth) || (blobHeight < minHeight) ||
                  (blobWidth > maxWidth) || (blobHeight > maxHeight))
              {
                labelsMap[i + 1] = 0;
                objectsToRemove++;
                blobs.RemoveAt(i);
              }
            }
            else
            {
              if (
                  ((blobWidth < minWidth) && (blobHeight < minHeight)) ||
                  ((blobWidth > maxWidth) && (blobHeight > maxHeight)))
              {
                labelsMap[i + 1] = 0;
                objectsToRemove++;
                blobs.RemoveAt(i);
              }
            }
          }
        }
        else
        {
          for (int i = objectsCount - 1; i >= 0; i--)
          {
            if (!filter.Check(blobs[i]))
            {
              labelsMap[i + 1] = 0;
              objectsToRemove++;
              blobs.RemoveAt(i);
            }
          }
        }
        int label = 0;
        for (int i = 1; i <= objectsCount; i++)
        {
          if (labelsMap[i] != 0)
          {
            label++;
            labelsMap[i] = label;
          }
        }
        for (int i = 0, n = objectLabels.Length; i < n; i++)
        {
          objectLabels[i] = labelsMap[objectLabels[i]];
        }
        objectsCount -= objectsToRemove;
        for (int i = 0, n = blobs.Count; i < n; i++)
        {
          blobs[i].ID = i + 1;
        }
      }
      if (objectsOrder != ObjectsOrder.None)
      {
        blobs.Sort(new BlobsSorter(objectsOrder));
      }
    }
public void ProcessImage ( UnmanagedImage image ) { imageWidth = image . Width ; imageHeight = image . Height ; BuildObjectsMap ( image ) ; CollectObjectsInfo ( image ) ; if ( filterBlobs ) { int [ ] labelsMap = new int [ objectsCount + 1 ] ; for ( int i = 1 ; i <= objectsCount ; i ++ ) { labelsMap [ i ] = i ; } int objectsToRemove = 0 ; if ( filter == null ) { for ( int i = objectsCount - 1 ; i >= 0 ; i -- ) { int blobWidth = blobs [ i ] . Rectangle . Width ; int blobHeight = blobs [ i ] . Rectangle . Height ; if ( coupledSizeFiltering == false ) { if ( ( blobWidth < minWidth ) || ( blobHeight < minHeight ) || ( blobWidth > maxWidth ) || ( blobHeight > maxHeight ) ) { labelsMap [ i + 1 ] = 0 ; objectsToRemove ++ ; blobs . RemoveAt ( i ) ; } } else { if ( ( ( blobWidth < minWidth ) && ( blobHeight < minHeight ) ) || ( ( blobWidth > maxWidth ) && ( blobHeight > maxHeight ) ) ) { labelsMap [ i + 1 ] = 0 ; objectsToRemove ++ ; blobs . RemoveAt ( i ) ; } } } } else { for ( int i = objectsCount - 1 ; i >= 0 ; i -- ) { if ( ! filter . Check ( blobs [ i ] ) ) { labelsMap [ i + 1 ] = 0 ; objectsToRemove ++ ; blobs . RemoveAt ( i ) ; } } } int label = 0 ; for ( int i = 1 ; i <= objectsCount ; i ++ ) { if ( labelsMap [ i ] != 0 ) { label ++ ; labelsMap [ i ] = label ; } } for ( int i = 0 , n = objectLabels . Length ; i < n ; i ++ ) { objectLabels [ i ] = labelsMap [ objectLabels [ i ] ] ; } objectsCount -= objectsToRemove ; for ( int i = 0 , n = blobs . Count ; i < n ; i ++ ) { blobs [ i ] . ID = i + 1 ; } } if ( objectsOrder != ObjectsOrder . None ) { blobs . Sort ( new BlobsSorter ( objectsOrder ) ) ; } }
Build object map from raw image data.
Build object map from raw image data .
// do actual objects map building // collect information about blobs // filter blobs by size if required // labels remapping array // check dimension of all objects and filter them // uncoupled filtering // coupled filtering // update labels remapping array // update remapping array // repair object labels // repair IDs // do we need to sort the list?
Unsupported pixel format of the source image.
Unsupported pixel format of the source image .
Thrown by some inherited classes if some image property other
than the pixel format is not supported. See that class's documentation or the exception message for details.
Thrown by some inherited classes if some image property other than the pixel format is not supported . See that class ' s documentation or the exception message for details .
image
UnmanagedImage
Source unmanaged binary image data.
Source unmanaged binary image data .
remarks
Processes the image and builds objects map, which is used later to extracts blobs.
Processes the image and builds objects map which is used later to extracts blobs .