**Name**

**flbg** Generates a (sequence of) codebook(s) from a training set of images using LBG (generalized Lloyd) algorithm

**Command Synopsis**

**flbg** [-s *CodeBookSize*] [-w *VectorWidth*] [-h *VectorHeight*] [-l] [-d *Decim*] [-e *Edge*] [-W *Weight*] [-M] [-p] [-A *TrainImage2*] [-B *TrainImage3*] [-C *TrainImage4*] [-D *TrainImage5*] [-E *TrainImage6*] [-F *TrainImage7*] [-G *TrainImage8*] [-i *InitRandCB*] [-r *RepeatRand*] [-f *NResCB*] [-g *NResResCB*] [-a *ResCodeBook*] [-b *ResResCodeBook*] *TrainImage1* *CodeBook*

-sCodeBookSize: Size of output codebook

-wVectorWidth: Width of vectors (default : 2)

-hVectorHeight: Height of vectors (default : 2)

-l : Take overlapping vectors in training images

-dDecim: Decimation factor in training images (for wavelet transform)

-eEdge: Do not take overlapping vectors if the distance to an edge is smaller than Edge (default : 0)

-WWeight: Weighting factors for the components of vector (fsignal)

-M : Generate codebooks of size equal to a power of two and smaller than Size

-p : Do not print information

-ATrainImage2: Training image (fimage)

-BTrainImage3: Training image (fimage)

-CTrainImage4: Training image (fimage)

-DTrainImage5: Training image (fimage)

-ETrainImage6: Training image (fimage)

-FTrainImage7: Training image (fimage)

-GTrainImage8: Training image (fimage)

-iInitRandCB: Initiate algorithm with a randomly drawn codebook of size InitRandCB

-rRepeatRand: Run the algorithm RepeatRand times (irrelevant if InitRandCB is smaller than 1)

-fNResCB: Index of first residual codebook (ResCodeBook)

-gNResResCB: Index of second residual codebook (ResResCodeBook)

-aResCodeBook: First residual codebook (fimage)

-bResResCodeBook: Second residual codebook (fimage)

TrainImage1: Training image (fimage)

CodeBook: Output codebook (fimage)

screen output : Quantization M.S.E. for training set

**Function Summary**

void flbg (Size , Width , Height , Lap , Decim , Edge , Weight , MultiCB , PrintSNR , Image2 , Image3 , Image4 , Image5 , Image6 , Image7 , Image8 , InitRandCB , RepeatRand , NResCB , NResResCB , ResCodeBook , ResResCodeBook , Image1 , CodeBook , MSE )

int *Size ;

int *Width , *Height ;

int *Lap ;

int *Decim ;

int *Edge ;

Fsignal Weight ;

int *MultiCB ;

int *PrintSNR ;

Fimage Image2 , Image3 , Image4 , Image5 , Image6 , Image7 , Image8 ;

int *InitRandCB ;

int *RepeatRand ;

int *NResCB , *NResResCB ;

Fimage ResCodeBook , ResResCodeBook ;

Fimage Image1 ;

Fimage CodeBook ;

float *MSE ;

**Description**

This module creates a training set of vectors extracted from one or several
images, and generates a codebook (or a set of codebooks)
for this training set using the LBG algorithm (see [GG92],
[LBG80]). The input images are read
in the files *TrainImage*, *TrainImage2*, ..., *TrainImage8*.
The generated codebook is stored in the *CodeBook* file.
It can be used for example for the vector quantization of images
with the *fvq* module.

The creation of the training set is made with the help of *mk_trainset*
module. See its documentation for the definition of the -w, -h, -l, -d and -e
options.

The codebook is generated using the *flbg_train* module. See the
documentation of this module for a brief description of the LBG algorithm
and the definition of the -s, -W, -M, -a, -b, -f and -g options.

The -i option has a different effect here compared to *flbg_train*.
When selected, a random codebook of size *InitRandCB* is generated
and used as initial codebook for the *flbg_train* module.
These means that all the components of all the vectors in this initial
codebooks are randomly drawn according to independent gaussian variables.
All these variables have the same mean and variance, which are the
empirical mean and variance of the components of the vectors
in *Trainset*. *InitRandCB* must be a strictly positive integer.

The -r option, when selected, has the same effect as if the *flbg*
module was run *RepeatRand* times, except that the resulting
codebooks (or sets of codebooks) are not stored on the disc,
except for the last one.
It is useful iff the -i option is selected with *InitRandCB* > 2
(otherwise the same computation is repeated *RepeatRand* times!).
The purpose of this option is to compare the rates and signal to noise ratios
when different initial codebooks are chosen.

**See Also**

`flbg_train`, `mk_codebook`, `mk_trainset`.

**Version 2.02**

Last Modification date : Thu Nov 29 20:23:57 2001

**Author**

Jean-Pierre D'Ales