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


Image Structure and Accessors

The Guile-CV procedures and methods related to image data structure, creating, accessing and copying images.

Procedures

im-make
im-make-channel
im-make-channels
im-copy
im-copy-channel
im-size_
im-width_
im-height_
im-n-channel_
im-channels_
im-channel
im-image?
im-gray?_
im-rgb?_
im-binary?
im-binary-channel?
im-=?
im-=-channel?
im-ref
im-fast-ref
im-set!
im-fast-set!
im-channel-offset
im-fast-channel-offset
im-channel-ref
im-fast-channel-ref
im-channel-set!
im-fast-channel-set!
im-collect

Description

A Guile-CV image is represented by a list containing the following elements:

(width height n-channel idata)

where idata is a list of n-channel elements, each element being a vector of (* width height) cells. More precisely, each element is an srfi-4 homogeneous numeric vector of 32 bit floats, called f32vector, knowing that f32 is the C type float.

The external representation (ie. read syntax) for idata vectors is #f32(…). As an example, a gray scale image of width 3 and height 2, initialized to 0.0 is represented by the following expression:

(3 2 1 (#f32(0.0 0.0 0.0 0.0 0.0 0.0)))

The n-channel is an integer >= 1, with no limit but the memory size. This said, most Guile-CV procedures and methods expect either GRAY scale (n-channel=1), or RGB (n-channel=3) images. For the later, the channels are Red, Green and Blue in that order.

Guile-CV provides usefull accessors for all these fields. However, very often, you will need them all, in which case your best friend is (ice-9 match), here is an example:

,use (cv)
(define image (im-make 4 3 3))
(match image
  ((width height n-chan idata)
   (match idata
     ((r g b)
      ... your code here ...))))

You will find many examples of such a ‘pattern’ in Guile-CV’s source code itself of course, along with some other ‘techniques’ that might be useful, so we invite you to read it, and if you do so: feedback, design and code review is more then welcome! This section describes what is in the module (cv idata).

Note that the (cv) module imports and re-exports, among may others, the public interface of (ice-9 match).

Procedures

Procedure: im-make width height n [value]
Procedure: im-make-channel width height [value]
Procedure: im-make-channels width height n [value]

Returns a new image, list of channels or channel.

Each channel is an srfi-4 homogeneous vector of 32 bit floats (f32vector), of width by height initialized to value. The default value is 0.0

Procedure: im-copy image
Procedure: im-copy-channel channel width height

Returns a new fresh copy of image or channel.

Method: im-size image

Returns the list of (width height n-channel)for image.

Method: im-width image
Method: im-height image
Method: im-n-channel image
Method: im-channels image
Procedure: im-channel image n

Returns, respectively the width, the height, n-channel, channels or the nth channel for image.

Procedure: im-image? image
Method: im-gray? image
Method: im-rgb? image

Returns #t if image is respectively a Guile-CV image, a GRAY scale or an RGB image.

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

Returns #t if i1 i2 i3 … or c1 c2 c3 … respectively are BINARY (Black and White) images or channels respectively.

Note that when more then one image or channel is passed, they must all be of the same size.

Procedure: im-=? [precision] i1 i2 i3 …
Procedure: im-=-channel? width height [precision] c1 c2 c3 …

Returns #t if i1 i2 i3 … or c1 c2 c3 … respectively are of the same size, have the same number of channels that all respectively contain the same values.

If the first argument is a number, it is used as the precision to compare pixel values. The default precision value is 1.0e-4. Note that if you are certain your images or channels contain ’discrete’ float values, you may pass 0.0 as the precision to be used, i which case values will be compared using = (instead of float=?, which is faster.

Procedure: im-ref image i j [k]
Procedure: im-fast-ref image i j [k]

Returns the pixel value stored at position i and j of the image channel k. The default value for k is 0.

im-fast-ref does not check the validity of its arguments: use it at your own risk.

Procedure: im-set! image i j [k] value
Procedure: im-fast-set! image i j [k] value

Returns nothing.

Sets the pixel value stored at position i and j of the image channel k to value. The default value for k is 0.

im-fast-set! does not check the validity of its arguments: use it at your own risk.

Procedure: im-channel-offset i j width height
Procedure: im-fast-channel-offset i j width

Returns the channel offset for the i and j indices, based on the width and height of the channel.

This procedure converts the matrix indices i and j to a vector offset for a channel of size width and height.

im-fast-channel-offset does not check the validity of its arguments: use it at your own risk.

Procedure: im-channel-ref channel i j width height
Procedure: im-fast-channel-ref channel i j width

Returns the pixel value stored at position i and j of the channel of size width and height.

im-fast-channel-ref does not check the validity of its arguments: use it at your own risk.

Procedure: im-channel-set! channel i j width height value
Procedure: im-fast-channel-set! channel i j width value

Returns nothing.

Sets the pixel at position i and j of channel of size width and height to value.

im-fast-channel-set! does not check the validity of its arguments: use it at your own risk.

Procedure: im-collect what i1 i2 i3 …

Returns a list of what collected from i1 i2 i3

The valid what synbols are:

size
width
height
n-channel
channels
chan-0, gray, red
chan-1, green
chan-2, blue
chan-k (*)

(*): whith k being a valid channel indice, [0 (- n 1)].


Next: Kernel Structure and Accessors, Up: Image Processing   [Contents][Index]