basic image processing on RGBA images where each pixel component is an
unsigned byte.

7.3.5.0. rgbaimage

(lsh/libimage/rgbaimage.lsh)

a rgbaimage is an idx3 of ubytes intended to store images. The last
dimension is 4, and contains the R, G, B, and Alpha channels
respectively.

7.3.5.1. Geometric Transforms

(lsh/libimage/rgbaimage.lsh)

A few functions to enlarge, reduce, resize, and rotate images.

7.3.5.1.0. (rgbaim-resize imwidthheightmode)

(lsh/libimage/rgbaimage.lsh)

resize an rgba image to any size using bilinear interpolation
Appropriate local averaging (smoothing) is performed for scaling factors
smaller than 0.5. If one of the desired dimensions is 0, an
aspect-ratio-preserving scaling is performed on the basis of the other
dimension. When both width and
height are non zero, the last parameter,
mode determines how they are interpreted.

if either width or
height is zero, mode is
ignored.

mode=0: fit the image into a width
by height frame while preserving the
aspect ratio

mode=1: scale the image to width
by height possibly changing the aspect
ratio

mode=2: width and
height are interpreted as scaling ratios

The sizes of the output image are rounded to nearest integers smaller
than the computed sizes, or to 1, whichever is largest.

7.3.5.1.1. (rgbaim-enlarge innlinncol)

(lsh/libimage/rgbaimage.lsh)

enlarges image in with integer ratios
nlin (vertical) ncol
(horizontal). the enlarged image is returned. The horizontal (resp.
vertical) size of the returned image is equal to the integer part of the
horizontal (resp vertical) size of in
divided by ncol (resp
nlin ). returns (copy-matrix in
) when enlarge rate is 1

7.3.5.1.2. (rgbaim-enlarge-into inoutnlinncol)

(lsh/libimage/rgbaimage.lsh)

enlarges image in with integer ratios
nlin (vertical) ncol
(horizontal) and write result in out .
The horizontal (resp. vertical) size of the output image is equal to the
integer part of the horizontal (resp vertical) size of
in divided by ncol (resp
nlin ).

7.3.5.1.3. (rgbaim-subsample innlinncol)

(lsh/libimage/rgbaimage.lsh)

subsamples image in with integer
ratios nlin (vertical)
ncol (horizontal). the subsampled image is returned. The
horizontal (resp. vertical) size of the returned image is equal to the
integer part of the horizontal (resp vertical) size of
in divided by ncol (resp
nlin ). returns (copy-matrix in
) when subsample rate is 1

7.3.5.1.4. (rgbaim-subsample-into inoutnlinncol)

(lsh/libimage/rgbaimage.lsh)

subsamples image in with integer
ratios nlin (vertical)
ncol (horizontal) and write result into
out . The horizontal (resp. vertical) size of the output
image is equal to the integer part of the horizontal (resp vertical)
size of in divided by
ncol (resp nlin ).

7.3.5.1.5. (rgbaim-rot90-left inp)

(lsh/libimage/rgbaimage.lsh)

rotate image inp by 90 to the left
(counter-clockwise) and return the result.

7.3.5.1.6. (rgbaim-rot90-right inp)

(lsh/libimage/rgbaimage.lsh)

rotate image inp by 90 to the right
(clockwise) and return the result.

((-flt-) x1 y1 x2 y2 x3 y3 x4 y4 p1 q1 p3 q3):
((-int-) background mode):
((-idx2- (-ubyte-)) in out):
RETURNS: Null
SIDE EFFECTS: <out>
AUTHOR: Y. LeCun
COMPILABLE: Yes
DESCRIPTION:
warp rgbaimage <in> through a geometric transformation that maps
a quadrilateral into a rectangle (bilinear transform).
The quadrilateral is specified by <x1> <y1> <x2> <y2> <x3> <y3> <x4> <y4>
(points are numbered clockwise starting from upper left).
The rectangle is specified by the upper left and lower right points
which are respectively <p1><q1> and <p3><q3>.
The result is put in <out>. Clipping is automatically performed.
pixels outside of the bounds of <in> are assumed to have the value
<background> (which must be an idx1 of ubyte of size 4).
<mode>=0: no antialiasing, <mode>=1: antialiasing with
bilinear interpolation (2 times slower).

7.3.5.1.11. (rgbaim-warp inoutbackgroundpipj)

(lsh/libimage/rgbaimage.lsh)

((-idx1- (-ubyte)) background):
((-idx3- (-ubyte-)) in out):
((-idx2- (-int-)) pi pj):
RETURNS: Null
SIDE EFFECTS: <out>
AUTHOR: Y. LeCun
COMPILABLE: Yes
DESCRIPTION:
Warps an image using <pi> and <pj> as tabulated coordinate transforms.
<in> and <out> are idx2 of ubytes. <background> is the value assumed outside
of the input image. <pi> and <pj> are integers idx whose dimensions must
be identical to the first two dimensions of <out>.
An output pixel at coordinate (x,y) takes the value of the input pixel at
coordinate <pj[x,y]>,<pi[x,y]>. If the values in <pi> and <pj> are non
integers the pixels are computed by bilinearly interpolating the input
image. The <pi> and <pj> matrices contain 32-bit integers which are
interpreted as 16 bit of integer part and 16 bits of fractinal part.
Integers values are assumed to fall in the center of each pixel,
so the upper left-hand corner of an image is at coordinate (-0.5, -0.5).

7.3.5.1.12. (rgbaim-warp-fast inoutbackgroundpipj)

(lsh/libimage/rgbaimage.lsh)

((-int-) background):
((-idx2- (-ubyte-)) in out):
((-idx2- (-int-)) pi pj):
RETURNS: Null
SIDE EFFECTS: <out>
AUTHOR: Y. LeCun
Warps an image using <pi> and <pj> as tabulated coordinate transforms.
<in> and <out> are idx2 of ubytes. <background> is the value assumed outside
of the input image. <pi> and <pj> are tabulated coordinates
This is essentially identical to rgbaim-warp, escept no bilinear
interpolation is performed (only a nearest neighbor rule is used).

7.3.5.1.13. (rgbaim-rotscale srcsxsydstdxdyanglecoeffbg)

(lsh/libimage/rgbaimage.lsh)

rotate, scale, and translate image src
and put result in dst . point
sx , sy in
src will be mapped to point dx
, dy in dst
. Image will be rotated clockwise by angle
degrees and scaled by coeff . Pixels
that fall off the boundary are clipped and pixels in the destination
that are not determined by a source pixel are set to color
bg (which must be an idx1 of ubytes of size 4). It is
generally preferable to call rgbaim-rotscale-rect before hand to get
appropriate values for dx ,
dy and for the size of dst
so that no pixel is clipped. Here is an example:

Given an input image of width w ,
height h , with a "hot" point at
coordinate cx and
cy , this function computes the width, height, and hot point
coordinates of the same image rotated by angle
and scaled by coeff so as to ensure
that no pixel in the rotated/scaled image will have negative coordinates
(so the image will not be clipped). wh
and cxcy which must be idx1 of floats
with two elements. This function should be called before
rgbaim-rotscale.

(-gptr- pin rez background):
(-int- indimi indimj inmodi inmodj ppi ppj):
SIDE EFFECTS: <rez>
DESCRIPTION:
returns a bilinearly interpolated RGBA pixel value for coordinate
<ppi> <ppj>. The image data is pointed to by <pin>, with
<indimi> <indimj> <inmodi> <inmodj> being the dimensions and modulos.
This function clips automatically if <ppi> <ppj> are outside of the
bounds by assuming the outside values are equal to <background>.
pixel values are ubytes, while coordinates are 32 bit fixed point
with 16 bit integer part and 16 bit fractional part.
The function does not use floating point arithmetics.

7.3.5.2. Color Processing

(lsh/libimage/rgbaimage.lsh)

7.3.5.2.0. (rgbaim-contbright inoutcb)

(lsh/libimage/rgbaimage.lsh)

correct contrast and brightness of image in
and put result in out (
in and out must be the same
size). c and b
are floats that will affect the brightness and contrast respectively.
c =1 and b =0 leave the
image unchanged. Each output pixel is computed as follows: output =
(input-128)*c + b + 128 (clipped between 0 and 255). An image can be
conveniently inverted by setting c to
-1 and b to 0.

7.3.5.2.1. (rgbaim-luminance inout)

(lsh/libimage/rgbaimage.lsh)

compute luminance of each pixel and put result in image
out the formula used is lum = 0.299 * R + 0.587 * G + 0.114 *
B

7.3.5.2.2. (rgbaim-lum2rgba inout)

(lsh/libimage/rgbaimage.lsh)

transform a grey-level image in (idx2
of flts) into an RGBA image. in and
out must have identical sizes, though no check of that is
done

7.3.5.2.3. (rgbaim-uvw inout)

(lsh/libimage/rgbaimage.lsh)

transform an RGBA image into an UVWA image, where the V component
contains the luminance information, and the U and W components
collectively contain the chrominance information. In the UVW color
coding scheme the euclidean distance is meant to reflect the subjective
"perceptual" distance. See Digital Image Processing by W. Pratt, page
66.

7.3.5.2.4. (rgbaim-saturate inminmaxout)

(lsh/libimage/rgbaimage.lsh)

Saturate pixel component values in image in
to the range [ min ,
max ]. Result is put in out
.

7.3.5.3. Blitting

(lsh/libimage/rgbaimage.lsh)

7.3.5.3.0. (rgbaim-blit xyinout)

(lsh/libimage/rgbaimage.lsh)

blit in into
out at position x ,
y with alpha blending. an alpha value of 0 in
in means opaque, 255 means totally transparent.

7.3.5.3.1. (rgbaim-blitcolor xyinrgbout)

(lsh/libimage/rgbaimage.lsh)

blit color defined by r ,
g , b using idx2
in as a stencil into RGBA image out
at position x y
The values in in must be between 0 and
255. if the value is 255, no paint is put in; if the value is 0, the
pixel takes the value specified by r ,
g , b .

7.3.5.4. Histograms

(lsh/libimage/rgbaimage.lsh)

7.3.5.4.0. (rgbaim-histo32 rgbaimppalcount)

(lsh/libimage/rgbaimage.lsh)

compute histogram of image rgbaim .
ppal must be a 32768 by 3 matrix of floats which will contain
the list of pixel values found. count
must be a 32768 matrix which will contain the corresponding pixel
counts. pixel colors are sorted by luminance. This function really
computes a 32768 color palette by assigning each pixel to the cube it
belongs to in the 32x32x32 RBG color cube. The color prototype assigned
to each cube is the mean of the pixels belonging to the cube.