7.3.5. RGBA Images of ubytes
|
(lsh/libimage/rgbaimage.lsh) |
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 im width height mode)
|
(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 in nlin ncol)
|
(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 in out nlin ncol)
|
(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 in nlin ncol)
|
(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 in out nlin ncol)
|
(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.
7.3.5.1.7. (rgbaim-rot180 inp)
|
(lsh/libimage/rgbaimage.lsh) |
rotate image inp by 180 degrees and
return the result.
7.3.5.1.8. (rgbaim-rot180-inplace in)
|
(lsh/libimage/rgbaimage.lsh) |
in-place 180 degree rotation of an image (caution: input image is
destroyed).
7.3.5.1.9. (rgbaim-crop in x y w h)
|
(lsh/libimage/rgbaimage.lsh) |
crop rectangle ( x ,
y , w ,
h ) from image in and
return the result (a copy).
7.3.5.1.10. (rgbaim-warp-quad in out background mode x1 y1 x2 y2 x3 y3 x4 y4 p1 q1 p3 q3)
|
(lsh/libimage/rgbaimage.lsh) |
((-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 in out background pi pj)
|
(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 in out background pi pj)
|
(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 src sx sy dst dx dy angle coeff bg)
|
(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:
(let* ((w (idx-dim m 1))
(h (idx-dim m 0))
(wh (int-matrix 2))
(cxcy (float-matrix 2))
(bg (ubyte-matrix 4)))
(rgbaim-rotscale-rect w h hotx-src hoty-src angle coeff wh cxcy)
(let ((z (ubyte-matrix (wh 1) (wh 0) 4)))
(rgbaim-rotscale m hotx-src hoty-src z (cxcy 0) (cxcy 1) angle coeff bg)))
7.3.5.1.14. (rgbaim-rotscale-rect w h cx cy angle coeff wh cxcy)
|
(lsh/libimage/rgbaimage.lsh) |
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.
7.3.5.1.15. Low-Level Geometric Transform Functions
|
(lsh/libimage/rgbaimage.lsh) |
These are unlikely to be used directly by most users.
7.3.5.1.15.0. (rgbaim-interpolate-bilin background pin indimi indimj inmodi inmodj ppi ppj rez)
|
(lsh/libimage/rgbaimage.lsh) |
Author(s): Y. LeCun
(-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 in out c b)
|
(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 in out)
|
(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 in out)
|
(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 in out)
|
(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 in min max out)
|
(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 x y in out)
|
(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 x y in r g b out)
|
(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 rgbaim ppal count)
|
(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.
7.3.5.4.1. Low-Level Histogram Functions
|
(lsh/libimage/rgbaimage.lsh) |
7.3.5.4.1.0. (rgbaim-init-lum2rgb )
|
(lsh/libimage/rgbaimage.lsh) |
build a table of 32x32x32 elements containing RGB cell indices in
ascending luminosity.
7.3.5.4.1.1. (rgbaim-lum2rgb n)
|
(lsh/libimage/rgbaimage.lsh) |
converts a luminosity index to a 5-bit RGB cell number.
7.3.5.5. Various Unusual Subsampling Functions
|
(lsh/libimage/rgbaimage.lsh) |
7.3.5.5.0. (rgbaim-subsample+ in nlin ncol)
|
(lsh/libimage/rgbaimage.lsh) |
same as rgbaim-subsample , but adds
one row and one column for lazy pixels
7.3.5.5.1. (rgbaim-subsample-med3 rgbaim)
|
(lsh/libimage/rgbaimage.lsh) |
subsample images by 3x3 using a median filter.
7.3.5.5.2. (rgbaim-med3-subopt rgbaim)
|
(lsh/libimage/rgbaimage.lsh) |
3x3 subsampling using the median smart median optimised in C for 3x3
squares: 1.3 sec
7.3.5.5.3. (rgbaim-med3-slow rgbaim)
|
(lsh/libimage/rgbaimage.lsh) |
3x3 subsampling using the median brute force median, with a 9 element
quicksort