An image segmentation software aiming at producing superpixels called waterpixels due to the use of the watershed algorithm.
Those waterpixels allow to regularly split an image into subregions, with the constraint that each subregion follows the contours of the elements in the image.
Contour detection is a first step in an image processing pipeline, which can be used for computer vision, facial recognition or robotics.
That is a C++ implementation using Qt5 for the GUI system and OpenCL for some GPU calculations.
The waterpixels generation method is based on the following research paper :
https://hal.archives-ouvertes.fr/hal-01212760/document
conan install . -s build_type=Release --build missing --install-folder=build
cmake -DCMAKE_TOOLCHAIN_FILE=${PATH_TO_VCPKG}/scripts/buildsystems/vcpkg.cmake -B build -S .
There are six steps to generate the waterpixels :
The gradient computation is done in the CIELAB color space, which better matches our human color differences perception, which is not the case in the RGB color space.
First thing is to go from RGB color space to XYZ color space :
Then we compute the X, Yn and Zn terms :
And at last, we go from the XYZ color space to the CIELAB color space by using the
following formulas :
Avec :
pour
pour
Once in the CIELAB color space, we can compute the gradient using a Sobel filter.
Sobel for gradient along X axis
-1 | 0 | +1 |
---|---|---|
-2 | 0 | +2 |
-1 | 0 | +1 |
Sobel for gradient along Y axis
+1 | +2 | +1 |
---|---|---|
0 | 0 | 0 |
-1 | -2 | -1 |
Finally, the gradient value for each pixel is
An hexagonal grid with a user defined size is layed upon the image.
Then comes the markers selection step.
For each cell, the greater set of connected pixels for which the gradient value is the lowest is selected and colored in green.
Those markers will serve as our seeds for the watershed algorithm done at step 5.
The Voronoï tesselation is done with the markers computed at the previous step.
Voronoï tesselation from the markers
One criteria must be satisfied by our waterpixels : they must be roughly equivalent in size and shape.
The regularization step is about merging the images obtained at steps 2 and 4.
Voronoï tesselation from the markers
Watershed : flood the image obtained at step 5 (our relief) with the markers computed at step 3 (our water sources).