Learn how to performs basic watershed segmentation with Pink
- pgm2GA | - GAwatershed |
- GA2khalimsky | - frame |
- nbcomp | - area |
Hint: you can use the How to Watershed with PINK section below to find some useful pink commands
Hint: step 3 is tricky. It needs the notion of a distance map of a binary object.
# To transform an image into a weighted edge graph:
pgm2GA im.pgm 0 relief.ga
TIP
The second argument (here 0) indicates how we proceed to weight the edges (maximum / minimum or intensity difference between pixels at the ends of each edge).
Is the choice of one weighting function more relevant than another? In which cases? What difference could it make to the output?
# To calculate a Watershed Line of a weighted edge graph
GAwatershed relief.ga watershed.ga
# To visualize the result, we switch to the Khalimsky grid
GA2khalimsky watershed.ga 0 watershed.pgm
TIP
To superimpose a segmentation (in the form of a binary image) on a grayscale image, we can use
surimp
be careful the two images must be the same size.
To resize an image to the desired size we can use zoom or make the image img.pgm
undergo a transition to a weighted graph and then to the Khalimsky grid.
pgm2GA img.pgm 0 img.ga
GA2khalimsky img.ga 0 imgRightSize.pgm
Basically, the distance map to a subset \(X\) of the space \(E\) is the image \(D_X\) on \(E\) defined, for every pixel \(x\) in \(E\) by \(D_X(x) = \min \{ \, d(x,y) \, | \, y \in X \, \}\) where \(d(x,y)\) denotes the (Euclidean) distance between \(x\) and \(y\).
The the distance map to \(X\) is an image where the value of each pixel \(x\) is the distance from this point to the closest point which belongs to the set \(X\).
To obtain the distance map of an object in Pink you can use the command dist
for example with the command:
dist X.pgm 1 distMapToX.pgm
If needed you can convert the resulting image to a byte image (i.e., an image with values between 0 and 255) with the command:
long2byte distMapToX.pgm 1 distMapToX_Byte.pgm
WARNING
If you calculate the map distance on an image that is too large, then the byte conversion will not work. The distances will be too large, resulting in an integer overflow.
Remind of the fantastic interactive seuil.tcl
.
areaclosing
heightminima
volmaxima
and inverse
area
nbcomp
Try frame
.