7.3.17.1. Color Segmentation and Quantization on RGBA Images
|
(lsh/libimage/rgbaim-greypage.lsh) |
a set of function for detecting the background and foreground colors in
a document image and for transforming them into grey-level images
suitable for recognition, segmentation, etc... essentially sets the
background to 0, the foreground to 256, the rest in the middle.
7.3.17.1.0. (rgbaim-project-greys rgbaim ubim polarity bsatur fsatur colors)
|
(lsh/libimage/rgbaim-greypage.lsh) |
transforms an rgb image into a grey image where the foreground is 256,
the background is 0, and the greys in between are between 256 and 0 the
resulting image can be used for segmentation and recognition.
rgbaim an idx3 of ubytes containing the input RGBA image.
ubim an idx2 of ubytes that will contain the result it should
be the same size as rgbaim
polarity determines the polarity of the image: 0 means light
background and dark foreground, 1 means dark background and light
forground, -1 should be passed if the polarity is unknown. In that case,
the color cluster with the most numerous pixels is assigned to the
background. pixel colors in rgbaim are
projected on a straight segment between two color prototypes computed
with K-means. The output pixels are given a grey value that depends on
their position along that segment. The function that maps positions on
the line to grey-levels is piece-wise linear saturation-type function.
It is controlled by two points A and B. below A, points are assigned the
value 0, above B they are assigned 256. in between they are mapped
linearly. the position of point A is determined by the argument
bsatur a value of 0 puts A on the background prototype, a
value of 0.5 puts it half way between the 2 prototypes. Point B is
controlled similarly: 0 puts it at the foreground prototype and 0.5 puts
it halfway. colors is a 2x3 matrix of
rgb color clusters for the background and foreground respectively.
7.3.17.1.1. (rgbaim-project-colors rgbaim rgbaim2 polarity bsatur fsatur colors)
|
(lsh/libimage/rgbaim-greypage.lsh) |
project the colors of an image onto a line joining two center clusters.
rgbaim an idx3 of ubytes containing the input RGBA image.
rgbaim2 contains the result image on output. it should be the same size
as rgbaim polarity determines the polarity of the image: 0
means light background and dark foreground, 1 means dark background and
light forground, -1 should be passed if the polarity is unknown. In that
case, the color cluster with the most numerous pixels is assigned to the
background. pixel colors in rgbaim are projected on a straight
segment between two color prototypes computed with K-means. The output
pixels are given a grey value that depends on their position along that
segment. The function that maps positions on the line to grey-levels is
piece-wise linear saturation-type function. It is controlled by two
points A and B. below A, points are assigned the value 0, above B they
are assigned 256. in between they are mapped linearly. the position of
point A is determined by the argument bsatur a value of 0 puts A
on the background prototype, a value of 0.5 puts it half way between
the 2 prototypes. Point B is controlled similarly: 0 puts it at the
foreground prototype and 0.5 puts it halfway. colors is a 2x3
matrix of rgb color clusters for the background and foreground
respectively.
7.3.17.1.2. (rgbaim-cluster-colors rgbaim ubim polarity bsatur fsatur proto weight variance)
|
(lsh/libimage/rgbaim-greypage.lsh) |
See rgbaim-project-greys for an explanation of the arguments. This
function performs color clustering, using the K-means algorithm. Results
in ubim .
proto : n_colors x 3 matrix = colors
of the clusters weight : n_colors
vector = weights of the Gaussian mixture for each cluster
variance : n_colors vector = variance parameter of each
cluster Gaussian distribution
See: (rgbaim-greypage rgbaim
ubim polarity
bsatur fsatur )
7.3.17.1.3. (rgbaim-quickquant rgbaim ubim ppal assign)
|
(lsh/libimage/rgbaim-greypage.lsh) |
quick color quantization of the pixels in rgbaim
to the colors in palette ppal . Each
pixel in the output image is a short whose value is the "label" of the
palette color that is closest to the input pixel.
assign is a vector of ints with the same first dimension as
ppal which contains the "label" for each palette color. This
function is relatively fast, but is approximate (the palette color
associated with an input color is not always the closest). In
particular, this function makes little sense if two palette colors are
in the same cell in the 32x32x32 RGB cube (which means
ppal should probably have less than 2^15 colors).
7.3.17.1.4. low-level color quantization functions.
|
(lsh/libimage/rgbaim-greypage.lsh) |
7.3.17.1.4.0. (rgbaim-greyquant rgbaim ubim proto polarity bsatur fsatur)
|
(lsh/libimage/rgbaim-greypage.lsh) |
transforms and RGB image into a grey image with uniform foreground and
background. proto is a 2x3 matrix of
floats containing two color prototypes for background and foreground
colors. rgbaim an idx3 of ubytes
containing the input RGBA image. ubim
an idx2 of ubytes that will contain the result it should be the same
size as rgbaim
polarity determines the polarity of the image: 0 means light
background and dark foreground, 1 means dark background and light
forground, -1 should be passed if the polarity is unknown. In that case,
the color cluster with the most numerous pixels is assigned to the
background. pixel colors in rgbaim are
projected on a straight segment between two color prototypes computed
with K-means. The output pixels are given a grey value that depends on
their position along that segment. The function that maps positions on
the line to grey-levels is piece-wise linear saturation-type function.
It is controlled by two points A and B. below A, points are assigned the
value 0, above B they are assigned 256. in between they are mapped
linearly. the position of point A is determined by the argument
bsatur a value of 0 puts A on the background prototype, a
value of 0.5 puts it half way between the 2 prototypes. Point B is
controlled similarly: 0 puts it at the foreground prototype and 0.5 puts
it halfway. colors is a 2x3 matrix of
rgb color clusters for the background and foreground respectively.
7.3.17.1.4.1. (rgbaim-projectcolors rgbaim rgbaim2 proto polarity bsatur fsatur)
|
(lsh/libimage/rgbaim-greypage.lsh) |
Basically does the same thing as rgbaim-greyquant
, but builds a color image instead of a gey image.
See: (rgbaim-greyquant rgbaim
ubim proto
polarity bsatur
fsatur )