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

The Guile-CV procedures and methods to process images.

`im-resize`

`im-resize-channel`

`im-rotate`

`im-rotate-channel`

`im-flip`

`im-flip-channel`

`im-invert`

`im-invert-channel`

`im-transpose`

`im-transpose-channel`

`im-normalize`

`im-normalize-channel`

`im-crop`

`im-crop-channel`

`im-crop-size`

`im-padd`

`im-padd-channel`

`im-padd-size`

`im-rgba->rgb`

`im-rgba->gray`

`im-rgb->gray`

`im-threshold`

`im-add`

`im-add-channel`

`im-subtract`

`im-subtract-channel`

`im-multiply`

`im-multiply-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-and`

`im-or`

`im-xor`

`im-complement`

`im-scrap`

`im-particles`

`im-particle-clean`

- Procedure:
**im-resize***image new-width new-height [#:i-mode 'bilinear]* - Procedure:
**im-resize-channel***channel width height new-width new-height [#:i-mode 'bilinear]* -
Returns a new image or chanbnel resized to

`new-width`,`new-height`.The interpolation mode

`#:i-mode`, can be one of:`none`

`bilinear`

`biquadratic`

`bicubic`

`? (fixme)`

- Procedure:
**im-rotate***image angle [#:i-mode 'bilinear]* - Procedure:
**im-rotate-channel***channel width height angle [#:i-mode 'bilinear]* -
Returns a new image or channel rotated by

`angle`.The

`angle`is in degrees:`+/-[0.0 360.0]`

.It is neccessary, for rotations other than multiples of 90°, to recalculate the target coordinates, since after the rotation, they might be floats. The ’next neighbor’ interpolation possible modes,

`#:i-mode`, are:`bilinear`

`biquadratic`

`bicubic`

`? (fixme)`

- Procedure:
**im-flip***image plane* - Procedure:
**im-flip-channel***channel width height plane* -
Returns a new image or channel flipped according to the selected

`plane`.Valid flipping

`plane`values are:`hori horizontal`

`vert vertical`

`both`

- Procedure:
**im-invert***image* - Procedure:
**im-invert-channel***channel width height* -
Returns a new inversed image or channel.

Calculating the inverse of an

`image`or a`channel`consist of applying the exponent function,`expt`

, to all pixel values, raising them to the power of -1.

- Procedure:
**im-transpose***image* - Procedure:
**im-transpose-channel***channel width height* -
Returns a new tranposed image or channel.

Transposing an

`image`or a`channel`consist of flipping it over its main diagonal. In the transposed result, switched in size, row values are the original column values and column values are the original row values.

- 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-crop***image left top right bottom* - Procedure:
**im-crop-channel***channel width height left top right bottom [#:new-w #f] [#:new-h #f]* -
Returns a new image, resulting of the crop of

`image`at`left`,`top`,`right`and`bottom`.

- Procedure:
**im-crop-size***width height left top right bottom* -
Returns a list,

`(new-width new-height)`

.Given the original image

`width`and`height`, this procedure checks that`left`,`top`,`right`and`bottom`are valid and return a list,`(new-width new-height)`

, otherwise, it raises an error.

- Procedure:
**im-padd***image left top right bottom [#:color '(0.0 0.0 0.0)]* - Procedure:
**im-padd-channel***channel width height left top right bottom [#:new-w #f] [#:new-h #f] [#:value 0.0]* -
Returns a new image or channel, respectively padding

`image`or`channel`by`left`,`top`,`right`and`bottom`pixels initialized respectively to`color`or`value`. Note that when`im-padd`

is called upon a`GRAY`

image,`color`is reduced to its corresponding gray`value`:`(/ (reduce + 0 color) 3)`

- Procedure:
**im-padd-size***width height left top right bottom* -
Returns a list,

`(new-width new-height)`

.Given the original image

`width`and`height`, this procedure checks that`left`,`top`,`right`and`bottom`are`>= 0`

and return a list,`(new-width new-height)`

, otherwise, it raises an error.

- Procedure:
**im-rgba->rgb***image [#:bg '(0.0 0.0 0.0)]* -
Returns a new RGB image.

The RGBA

`image`channels are first normalized. The new RGB channels are obtained by applying the following pseudo code algorithm:R = (((1 - Source.A) * BG.R) + (Source.A * Source.R)) * 255.0 G = (((1 - Source.A) * BG.G) + (Source.A * Source.G)) * 255.0 B = (((1 - Source.A) * BG.B) + (Source.A * Source.B)) * 255.0

- Procedure:
**im-rgba->gray***image [#:bg '(0.0 0.0 0.0)]* -
Returns a new GRAY image.

This procedure is implemented as

`(im-rgb->gray (im-rgba->rgb image)).`

- Procedure:
**im-rgb->gray***image* -
Returns a new GRAY image.

- Procedure:
**im-threshold***image threshold [#:bg 'black] [#:prec 1.0e-4]* -
Returns a new BLACK and WHITE image.

Valid

`#:bg`values are`'(black white)`

, the default is`black`

. If`image`is an RGB image, im-rgb->gray is first called.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.

- 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-multiply***image val* - Method:
**im-multiply***i1 i2 i3 …* - Method:
**im-multiply-channel***channel width height val* - Method:
**im-multiply-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 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.

The scalar method divides each pixel of

`image`or`channel`by`val`.Technically speaking, there is no such thing as matrix division. Dividing a matrix by another matrix is an undefined function. The closest equivalent is multiplying by the inverse of another matrix.

So, the matrix divide methods performs the linear algebra matrix multiplication of

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

- 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-and***i1 i2 i3 …* - Procedure:
**im-or***i1 i2 i3 …* - Procedure:
**im-xor***i1 i2 i3 …* -
Returns

`image`if one argument only, otherwise, it returns a new image, as the result of computing the logical`AND`

,`OR`

or`XOR`

of all images.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`, 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`i1`when it is`> 0.0`

, otherwise, they are set to the corresponding pixel mean value of all other images.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`

pixel value, until all images passed in arguments have been processed^{6}.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!

- Procedure:
**im-complement***image* -
Returns a new image.

This procedure computes the mathematical complement of

`image`, which for Guile-CV means that for each pixel of each channel, the new value is`(- 255.0 pixel-value)`

.

- Procedure:
**im-scrap***image val [#:pred <] [#:con 8] [#:bg 'black]* -
Returns a new image.

Scraping an image is the operation of removing objects of size

`val`, according to`con`,`bg`and`pred`.Using the above mentioned arguments,

`im-scrap`

first calls im-label using`con`and`bg`, then calls im-features. The`area`

feature of each object is then compared to`val`using`pred`, and the object is eliminated if the result is`#t`

.Note that

`image`must be a binary image.

- Procedure:
**im-particles***image features [#:clean #t]* -
Returns a list of images.

Each returned image is a ‘

`particle`’, which is a subpart of`image`determined by its bounding box, given by the`left`

`top`

`right`

`bottom`

values of the corresponding ‘`entry`’ in`features`(see im-features for a complete description of a feature value list.When

`#:clean`is`#t`

, which is the default, im-particle-clean is called upon each particle (see below for a description of the expected result).

- Procedure:
**im-particle-clean***particle* -
Returns a new image.

Cleaning a

`particle`(which is an image) means detecting and removing any object(s) that is(are) not connected to the ‘`particle`’ itself.This procedure is based on the property that in a ‘

`particle`’, which is an (sub)image resulting from a im-crop based on the bounding box coordinates as returned by`im-features`

, there precisely is one object that, if you call`im-features`

upon`particle`, would have its bounding box coordinates being the entire`particle`. In other words, if you call`im-particle-clean`

upon an image that is not a ‘`particle`’, the result will just be a black image.

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: Features, Previous: Import Export, Up: Guile-CV [Contents][Index]