Next: , Previous: , Up: Guile-CV   [Contents][Index]

3.2.7 Segmentation

The Guile-CV procedures and methods related to segmentation.


Procedure: im-label image [#:con 8] [#:bg 'black]
Procedure: im-label-channel channel width height [#:con 8] [#:bg 'black]
Procedure: im-label-all image [#:con 8]
Procedure: im-label-all-channel channel width height [#:con 8]

Returns two values: a new GRAY image or GRAY channel, and the total number of objects.

The im-label and im-label-channel procedures label foreground objects in the binary image. In the new image or channel, 0.0 indicates a background pixel, 1.0 indicates that the pixel belongs to object number 1, 2.0 that the pixel belongs to object number 2, etc.

The im-label-all and im-label-all-channel procedures label all objects in the binary image, with no specific distinction for any background value. As a result, these two procedures will label not only the continuous background, if any, but also any hole(s). As an example, they are used by im-fill, defined in the module (cv morphology), which you may have a look at for a better understanding of how it works.

Two pixels belong to the same object if they are neighbors. By default the algorithm uses 8-connectivity to define a neighborhood, but this can be changed through the keyword argument #:con, which can be either 4 or 8.

pp-17-bf pp-17-bf-label pp-17-bf-label-all

Here above, left being the original image, you can see the difference between im-label (1 object) and im-label-all (6 objects). Note that we had to run im-threshold on the original image first (all labeling procedures take a binary image (or channel) as their mandatory argument), for the record, we used 128 as the threshold value.

Procedure: im-canny image [#:sigma 1.0] [#:threshold 0.0] [#:marker 255.0]
Procedure: im-canny-channel channel width height [#:sigma 1.0] [#:threshold 0.0] [#:marker 255.0]

Returns a new image or channel.

Detect and mark edges using a Canny Edge Detector algorithm: (a) compute the image Gaussian gradient using sigma, (b) remove edges whose strength is below threshold, then for all remaining edges, (d) remove the non-local maxima (edge thinning) and (e) set their intensity using marker.

edx edx-canny-s1.0-t0.0-m255.0 edx-canny-s1.0-t8.0-m255.0 edx-canny-s1.5-t8.0-m255.0 edx-canny-s1.0-t8.0-m96.0

Here above, left being the original tif image6, you can see the difference between im-canny called using the default values, then using #:threshold 8, and finally both #:sigma 1.5 and #:threshold 8. The last example is an illustration of the use of #:marker 96.07.



Actually, all images displayed in the documentation are png images, though all described im-canny calls where performed on the original tif image. This is because in Guile-CV, all images are 32bit float images, and when saved as tif, all values are preserved (as opposed to being normalized): however, most viewers do not handle floating point pixel values (they donĀ“t know how to scale the values, which may be negative, fractional...). In order to show the results in the documentation, even though all computations of this example were made upon the original tif image, they were saved to png (which normalize all pixel values to [0 255].).


Note that in order to show the result in the documentation, we had to manually set one pixel of one of the edges to 255.0: this is because, just as we explained in the previous footnote, to be able to display the image in the documentation, we had to save the image as png, which does normalize all values: if you do not set one of the pixels of one edge to 255.0, all markers values would be normalized to 255.0, there by loosing the original marker value.

Next: , Previous: , Up: Guile-CV   [Contents][Index]