Next: , Previous: , Up: Image Processing   [Contents][Index]


Process

The Guile-CV procedures and methods to process images.

Procedures

im-threshold
im-scrap
im-add
im-add-channel
im-subtract
im-subtract-channel
im-mtimes
im-mtimes-channel
im-times
im-times-channel
im-divide
im-divide-channel
im-range
im-range-channel
im-min
im-min-channel
im-max
im-max-channel
im-map
im-map-channel
im-reduce
im-reduce-channel
im-normalize
im-normalize-channel
im-and
im-and-channel
im-or
im-or-channel
im-xor
im-xor-channel
Procedure: im-threshold image threshold [#:bg 'black]

Returns a new BLACK and WHITE image.

The image argument can either be a GRAY or an an RGB image, in which case each pixel is converted to GRAY as it is processed. Valid #:bg values are black (the default) and white.

Pixels for which the original value is >= threshold are set to 255.0 if #:bg is 'black, and set to 0.0 if #:bg is 'white. The other pixels are set to 0.0 or 255.0 respectively.

Procedure: im-scrap image size [#:pred <] [#:con 8] [#:bg 'black] [#:exclude-on-edges #f]

Returns a new image.

Scraping an image is the operation of removing objects depending on their size (in pixels). When exclude-on-edges is #t, all objects that are on any edges are also removed.

The procedure first calls im-label using con and bg, then calls im-features. The area feature of each object is then compared to size using pred and the object is removed if the result is #t.

Note that image must be a binary image.

Method: im-add image val
Method: im-add i1 i2 i3 …
Method: im-add-channel channel width height val
Method: im-add-channel width height c1 c2 c3 …

Returns a new image or channel.

Performs the scalar addition of image with val or the matrix addition of i1 i2 i3 … or c1 c2 c3 … respectively.

Method: im-subtract image val
Method: im-subtract i1 i2 i3 …
Method: im-subtract-channel channel width height val
Method: im-subtract-channel width height c1 c2 c3 …

Returns a new image or channel.

Performs the scalar subtraction of image with val or the matrix subtraction of i1 i2 i3 … or c1 c2 c3 … respectively.

Method: im-times image val
Method: im-times i1 i2 i3 …
Method: im-times-channel channel width height val
Method: im-times-channel c1 w1 h1 c2 w2 h2 c3 w3 h3 …

Returns a new image or channel.

Performs the scalar multiplication of image with val or the element by element multiplication of i1 i2 i3 … or c1 c2 c3 … respectively.

Procedure: im-mtimes i1 i2 i3 …
Procedure: im-mtimes-channel width height c1 c2 c3 …

Returns a new image or channel.

Performs matrix multiplication of i1 i2 i3 … or c1 w1 h1 c2 w2 h2 c3 w3 h3 … recursively. The number of lines of the next image must equal the number of columns of the previous intermediate result.

Method: im-divide image val
Method: im-divide i1 i2 i3 …
Method: im-divide-channel channel width height val
Method: im-divide-channel c1 w1 h1 c2 w2 h2 c3 w3 h3 …

Returns a new image or channel.

Performs the scalar division of image with val or the element by element division of i1 i2 i3 … or c1 c2 c3 … respectively.

It is the user responsibility to insure that none of the c2 c3 … values is zero.

Procedure: im-mdivide i1 i2 i3 …
Procedure: im-mdivide-channel width height c1 c2 c3 …

Returns a new image or channel.

Performs the matrix multiplication of i1 or c1 by the inverse of i2 i3 … or c2 c3 … recursively. The number of lines of the next image must equal the number of columns of the previous intermediate result19.

It is the user responsibility to insure that none of the c2 c3 … values is zero.

Procedure: im-range image
Procedure: im-range-channel channel width

Returns a list of six values (min row col max row col) if image is GRAY, and a list of list of these values if image is RGB or for any n-chan > 1 images.

Procedure: im-min image
Procedure: im-max image
Procedure: im-min-channel channel width
Procedure: im-max-channel channel width

Returns three multiple values if image is GRAY: min row col or max row col respectively. If image is RGB or for any n-chan > 1 images, it returns a list of list of these values.

Procedure: im-map proc i1 i2 i3 …
Procedure: im-map-channel proc width height c1 c2 c3 …

Returns a new image or channel.

Apply proc to each pixel value of each channel of i1 (if only two arguments are given), or to the corresponding pixel values of each channels of i1 i2 i3 … (if more than two arguments are given).

Procedure: im-reduce image proc default
Procedure: im-reduce-channel channel proc default

Returns one value if image is GRAY. If image is RGB or for any n-chan > 1, it returns a list of values.

If image is empty, im-reduce returns default (this is the only use for default). If image has only one pixel, then the pixel value is what is returned. Otherwise, proc is called on the pixel values of image.

Each proc call is (proc elem prev), where elem is a pixel value from the channel (the second and subsequent pixel values of the channel), and prev is the returned value from the previous call to proc. The first pixel value - for each channel - is the prev for the first call to proc.

For example:

,use (cv)
(im-load "edx.png")
-|
$2 = (128 128 1 (#f32(4.0 26.0 102.0 97.0 58.0 10.0 9.0 21.0 # …)))
(im-reduce $2 + 0)
-|
$3 = 556197.0
Procedure: im-normalize image [#:value 255.0]
Procedure: im-normalize-channel channel width height [#:value 255.0]

Returns a new normalized image or channel.

Normalizing an image or a channel consist of dividing all pixels by a value so they all fall in the [0.0 -> 1.0] range. The default #:value is 255.0.

Procedure: im-and i1 i2 i3 …
Procedure: im-and-channel width height c1 c2 c3 …
Procedure: im-or i1 i2 i3 …
Procedure: im-or-channel width height c1 c2 c3 …
Procedure: im-xor i1 i2 i3 …
Procedure: im-xor-channel width height c1 c2 c3 …

Returns image if one argument only, otherwise, it returns a new image or channel, as the result of computing the logical AND, OR or XOR of all images or channels.

In the case of AND, for all positive results, the pixel values (of each channel) of the new image are set to the one obtained from i1 or c1 respectively, and 0.0 otherwise.

In the case of OR, the pixel values (of each channel) of the new image are set to the one obtained from the first non zero ii or ci respectively, otherwise it is set to 0.0.

In the case of XOR, the pixel values (of each channel) of the new image are set to the value obtained from successively computing (logior (logand a (- 255 b)) (logand (- 255 a) b)) where a would be the previous result and b the current image or channel pixel value, until all images passed in arguments have been processed20.

All images must have the same width, height and n-channel.

There are, of course, scientific use and examples of images logical XOR, and that is why Guile-CV is being developed for, but let’s have a bit of fun here, and see if our levitating GNU likes apples!

emacs-1

Footnotes

(19)

Technically speaking, there is no such thing as matrix division. Dividing a matrix by another matrix is an undefined function. The closest equivalent is to multiply the matrix by the inverse of the other matrix.

(20)

Note that there is no mathematically valid XOR operation on floating points, hence as they are ‘accessed’, pixel values are converted to integer, using float->int, defined in the (cv support libguile-cv) module).


Next: Transform, Previous: Filter, Up: Image Processing   [Contents][Index]