# Selecting and Sorting Blobs

This code snippet shows how to build blobs, select some of them and sort the selected ones.

## C++

```cpp
#include <eVision/EasyObject/EasyObject2/EImageEncoder.h>
```

```cpp
using namespace eVision;
// Image constructor
EImageBW8 srcImage;
// Image encoder
EImageEncoder encoder;
// Coded image
ECodedImage2 codedImage;
// ...
// Encode the source image
encoder.Encode(srcImage, codedImage);
// Create a blob selection
EObjectSelection selection;
selection.AddObjects(codedImage);
// Remove the Small blobs
selection.RemoveUsingUnsignedIntegerFeature(EFeature_Area, 100, ESingleThresholdMode_Less);
// Retrieve the number of remaining blobs
unsigned int numBlobs = selection.GetElementCount();
// Sort the remaining blobs based on their area
selection.Sort(EFeature_Area, ESortDirection_Ascending);
// Retrieve the selected blobs
for (unsigned int index = 0; index < numBlobs; index++)
{
  float centerX = selection.GetElement(index).GetGravityCenterX();
  float centerY = selection.GetElement(index).GetGravityCenterY();
}
```

#### SEE ALSO
[`EObjectSelection::AddObjects`](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#ae15c3a7923c9fc7d876dc2715e71d34a) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a592cf2873995153541386fd91568b7e0) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a2a5ee1b5f478b4a48f0e2d9299a3bf0e), [`EObjectSelection::GetElementCount`](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#a4b9713df3d3c59a261961443965b53ca) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a0ae0e9796214d7412f01dd7dd689cf53) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a41d992aae7e9a3635d0c24fc43146d04), [`EObjectSelection::RemoveUsingUnsignedIntegerFeature`](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#aef104613adcfca8efa3ad4ba16003cd9) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a4faf090396b97351b9a932f08e9dade2) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a2bd164e1a32eec05d1250698e57786fd), [`EObjectSelection::Sort`](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#ac1b810a7e8833f62e2ae49a2ee9137a1) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a52eb89349ae149d959591aa6f352fe9e) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a286e7a0ec3040a189e65c7910473cff1)

## C#

```cs
using eVision;
```

```cs
// Image constructor
EImageBW8 srcImage = new EImageBW8();
// Image encoder
EImageEncoder encoder = new EImageEncoder();
// Coded image
ECodedImage2 codedImage = new ECodedImage2();
// ...
// Encode the source image
encoder.Encode(srcImage, codedImage);
// Create a blob selection
EObjectSelection selection = new EObjectSelection();
selection.AddObjects(codedImage);
// Remove the small blobs
selection.RemoveUsingUnsignedIntegerFeature(EFeature.Area, 100, ESingleThresholdMode.Less);
// Retrieve the number of remaining blobs
uint numBlobs = selection.ElementCount;
// Sort the remaining blobs based on their area
selection.Sort(EFeature.Area, ESortDirection.Ascending);
// Retrieve the selected blobs
for (uint index = 0; index < numBlobs; index++)
{
  float centerX = selection.GetElement(index).GravityCenterX;
  float centerY = selection.GetElement(index).GravityCenterY;
}
```

#### SEE ALSO
[`EObjectSelection.AddObjects`](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a592cf2873995153541386fd91568b7e0) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#ae15c3a7923c9fc7d876dc2715e71d34a) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a2a5ee1b5f478b4a48f0e2d9299a3bf0e), [`EObjectSelection.ElementCount`](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a0ae0e9796214d7412f01dd7dd689cf53) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#a4b9713df3d3c59a261961443965b53ca) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a41d992aae7e9a3635d0c24fc43146d04), [`EObjectSelection.RemoveUsingUnsignedIntegerFeature`](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a4faf090396b97351b9a932f08e9dade2) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#aef104613adcfca8efa3ad4ba16003cd9) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a2bd164e1a32eec05d1250698e57786fd), [`EObjectSelection.Sort`](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a52eb89349ae149d959591aa6f352fe9e) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#ac1b810a7e8833f62e2ae49a2ee9137a1) [<sub>Python</sub>](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a286e7a0ec3040a189e65c7910473cff1)

## Python

```py
import eVision
# Image constructor
src_image = eVision.EImageBW8()
# Image encoder
encoder = eVision.EImageEncoder()
# Coded image
codedImage = eVision.ECodedImage2()
# ...
# Encode the source image
encoder.Encode(src_image, codedImage)
# Create a blob selection
selection = eVision.EObjectSelection()
selection.AddObjects(codedImage)
# Remove the small blobs
selection.RemoveUsingUnsignedIntegerFeature(eVision.EFeature.Area, 100, eVision.ESingleThresholdMode.Less)
# Retrieve the number of remaining blobs
numBlobs = selection.ElementCount
# Sort the remaining blobs based on their area
selection.Sort(eVision.EFeature.Area, eVision.ESortDirection.Ascending)
# Retrieve the selected blobs
for index in range(numBlobs):
    centerX = selection.GetElement(index).GravityCenterX
    centerY = selection.GetElement(index).GravityCenterY
```

#### SEE ALSO
[`EObjectSelection.AddObjects`](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a2a5ee1b5f478b4a48f0e2d9299a3bf0e) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#ae15c3a7923c9fc7d876dc2715e71d34a) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a592cf2873995153541386fd91568b7e0), [`EObjectSelection.ElementCount`](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a41d992aae7e9a3635d0c24fc43146d04) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#a4b9713df3d3c59a261961443965b53ca) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a0ae0e9796214d7412f01dd7dd689cf53), [`EObjectSelection.RemoveUsingUnsignedIntegerFeature`](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a2bd164e1a32eec05d1250698e57786fd) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#aef104613adcfca8efa3ad4ba16003cd9) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a4faf090396b97351b9a932f08e9dade2), [`EObjectSelection.Sort`](../../../../doxygen_python/classeVision_1_1EObjectSelection.html#a286e7a0ec3040a189e65c7910473cff1) [<sub>C++</sub>](../../../../doxygen_cpp/classeVision_1_1EObjectSelection.html#ac1b810a7e8833f62e2ae49a2ee9137a1) [<sub>.NET</sub>](../../../../doxygen_cs/classeVision_1_1EObjectSelection.html#a52eb89349ae149d959591aa6f352fe9e)
