Skip to content

Image segmentation method for the generation of superpixels called waterpixels which follow an image contours.

License

Notifications You must be signed in to change notification settings

Bicyclette/Waterpixels

Repository files navigation

Waterpixels

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

Dependencies

Build

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 .

Waterpixels generation method

There are six steps to generate the waterpixels :

Step 1 : Load an image

Original image
image

Step 2 : Compute the image gradient

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 :

$$ \begin{bmatrix} X\\ Y\\ Z\\ \end{bmatrix} \equal \begin{bmatrix} 0.618 & 0.177 & 0.205 \\ 0.299 & 0.587 & 0.114 \\ 0.0 & 0.056 & 0.944 \\ \end{bmatrix} \times \begin{bmatrix} R\\ G\\ B\\ \end{bmatrix} $$

Then we compute the X, Yn and Zn terms :

$$ \begin{bmatrix} Xn\\ Yn\\ Zn\\ \end{bmatrix} \equal \begin{bmatrix} 0.618 & 0.177 & 0.205 \\ 0.299 & 0.587 & 0.114 \\ 0.0 & 0.056 & 0.944 \\ \end{bmatrix} \times \begin{bmatrix} 255\\ 255\\ 255\\ \end{bmatrix} $$

And at last, we go from the XYZ color space to the CIELAB color space by using the
following formulas :

$L = 116 \times (\frac{Y}{Yn})^\frac{1}{3} - 16$ pour $\frac{Y}{Yn} > 0.008856$

$L = 903.3 \times \frac{Y}{Yn}$ pour $\frac{Y}{Yn} \leq 0.008856$

$a = 500 \times(f(\frac{X}{Xn}) - f(\frac{Y}{Yn}))$

$b = 200 \times(f(\frac{Y}{Yn}) - f(\frac{Z}{Zn}))$

Avec :
pour $t > 0.008856$, $f(t) = \sqrt[3]{t}$
pour $t \leq 0.008856$, $f(t) = 7.7787 \times t + \frac{16}{116}$

Once in the CIELAB color space, we can compute the gradient using a Sobel filter.

Sobel for gradient along X axis $Gx$ :

-1 0 +1
-2 0 +2
-1 0 +1

Sobel for gradient along Y axis $Gy$ :

+1 +2 +1
0 0 0
-1 -2 -1

Finally, the gradient value for each pixel is $G = sqrt(Gx^2 + Gy^2)$

Gradient
gradient

Step 3 : Compute a grid and cell markers

An hexagonal grid with a user defined size is layed upon the image.

Grid
hexGrid

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.

Markers in each grid cell
markers

Step 4 : Voronoï tesselation

The Voronoï tesselation is done with the markers computed at the previous step.

Voronoï tesselation from the markers
voronoi

Step 5 : Gradient regularization

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
reg_grad

Step 6 : Image segmentation with the watershed algorithm

Watershed : flood the image obtained at step 5 (our relief) with the markers computed at step 3 (our water sources).

Waterpixels
waterpixels

About

Image segmentation method for the generation of superpixels called waterpixels which follow an image contours.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published