Example #1
0
 public void ProcessImage(UnmanagedImage image)
 {
     imageWidth  = image.Width;
     imageHeight = image.Height;
     BuildObjectsMap(image);
     CollectObjectsInfo(image);
     if (filterBlobs)
     {
         int[] array = new int[objectsCount + 1];
         for (int i = 1; i <= objectsCount; i++)
         {
             array[i] = i;
         }
         int num = 0;
         if (filter == null)
         {
             for (int num2 = objectsCount - 1; num2 >= 0; num2--)
             {
                 int width  = blobs[num2].Rectangle.Width;
                 int height = blobs[num2].Rectangle.Height;
                 if (!coupledSizeFiltering)
                 {
                     if (width < minWidth || height < minHeight || width > maxWidth || height > maxHeight)
                     {
                         array[num2 + 1] = 0;
                         num++;
                         blobs.RemoveAt(num2);
                     }
                 }
                 else if ((width < minWidth && height < minHeight) || (width > maxWidth && height > maxHeight))
                 {
                     array[num2 + 1] = 0;
                     num++;
                     blobs.RemoveAt(num2);
                 }
             }
         }
         else
         {
             for (int num3 = objectsCount - 1; num3 >= 0; num3--)
             {
                 if (!filter.Check(blobs[num3]))
                 {
                     array[num3 + 1] = 0;
                     num++;
                     blobs.RemoveAt(num3);
                 }
             }
         }
         int num4 = 0;
         for (int j = 1; j <= objectsCount; j++)
         {
             if (array[j] != 0)
             {
                 num4 = (array[j] = num4 + 1);
             }
         }
         int k = 0;
         for (int num5 = objectLabels.Length; k < num5; k++)
         {
             objectLabels[k] = array[objectLabels[k]];
         }
         objectsCount -= num;
         int l = 0;
         for (int count = blobs.Count; l < count; l++)
         {
             blobs[l].ID = l + 1;
         }
     }
     if (objectsOrder != 0)
     {
         blobs.Sort(new BlobsSorter(objectsOrder));
     }
 }
Example #2
0
        public override void OnProcess()
        {
            imageWidth  = Source.Width;
            imageHeight = Source.Height;

            // do actual objects map building
            BuildObjectsMap(Source);

            // collect information about blobs
            CollectObjectsInfo(Source);

            // filter blobs by size if required
            if (filterBlobs)
            {
                // labels remapping array
                int[] labelsMap = new int[objectsCount + 1];
                for (int i = 1; i <= objectsCount; i++)
                {
                    labelsMap[i] = i;
                }

                // check dimension of all objects and filter them
                int objectsToRemove = 0;

                if (filter == null)
                {
                    for (int i = objectsCount - 1; i >= 0; i--)
                    {
                        int blobWidth  = (int)blobs[i].Rectangle.Width;
                        int blobHeight = (int)blobs[i].Rectangle.Height;

                        if (coupledSizeFiltering == false)
                        {
                            // uncoupled filtering
                            if (
                                (blobWidth < minWidth) || (blobHeight < minHeight) ||
                                (blobWidth > maxWidth) || (blobHeight > maxHeight))
                            {
                                labelsMap[i + 1] = 0;
                                objectsToRemove++;
                                blobs.RemoveAt(i);
                            }
                        }
                        else
                        {
                            // coupled filtering
                            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);
                        }
                    }
                }

                // update labels remapping array
                int label = 0;
                for (int i = 1; i <= objectsCount; i++)
                {
                    if (labelsMap[i] != 0)
                    {
                        label++;
                        // update remapping array
                        labelsMap[i] = label;
                    }
                }

                // repair object labels
                for (int i = 0, n = objectLabels.Length; i < n; i++)
                {
                    objectLabels[i] = labelsMap[objectLabels[i]];
                }

                objectsCount -= objectsToRemove;

                // repair IDs
                for (int i = 0, n = blobs.Count; i < n; i++)
                {
                    blobs[i] = new Blob(i + 1, blobs[i]);
                }
            }

            // do we need to sort the list?
            if (objectsOrder != ObjectsOrder.None)
            {
                blobs.Sort(new BlobsSorter(objectsOrder));
            }
        }