DjVu Layered - image bundle on the mask + foreground + background using "Multi-scale binarization".
Degradation of images on layers mask, foreground and background by cluster analysis with a gradual decrease in block size.
In addition to DjVuL, several more threshold methods are supported: BiMod, Sauvola, Blur threshold.
submodules:
$ git submodule init
$ git submodule update
build dependencies:
- build-essential
- cmake
$ sudo apt-get install build-essential cmake
$ mkdir build
$ cd build
$ cmake ..
$ make
The first parameter specifies the path to the image. The second parameter is the resulting BW mask. [optional: The third parameter is the background. The fourth parameter is foreground.]
./stbdjvul [options] image_in bw_mask_out.png [bg_out.png] [fg_out.png] [bgmask_out.png] [fgmask_out.png]
./stbdjvul lena.png lena.mask.png lena.bg.png lena.fg.png
Load: lena.png
image: 256x256:3
BG: 86x86:3
FG: 43x43:3
DjVuL... 7 level
Save png: lena.mask.png, lena.bg.png, lena.fg.png.
./stbdjvul -c 1 lena.png lena.mask.c1.png lena.bg.c1.png lena.fg.c1.png
Load: lena.png
image: 256x256:3
BG: 86x86:3
FG: 43x43:3
DjVuL... 7 level
Save png: lena.mask.c1.png, lena.bg.c1.png, lena.fg.c1.png.
This utility includes a mode for splitting an image into a BG and a FG based on an existing mask (ground). The mask can be corrected.
./stbdjvul -m 1 -r lena.png lena.mask.png lena.bg.g.png lena.fg.g.png
Load: lena.png
image: 256x256:3
Load: lena.mask.png
mask: 256x256:3
BG: 86x86:3
FG: 43x43:3
DjVuL ground... 7 level
Save png: lena.mask.png, lena.bg.g.png, lena.fg.g.png.
This utility includes a mode for reconstruct an image on an existing mask, BG and FG (reconstruct).
./stbdjvul -m 2 lena.r.png lena.mask.png lena.bg.png lena.fg.png
Load: lena.mask.png
mask: 256x256:3
Load: lena.bg.png
BG: 86x86:3
Load: lena.fg.png
FG: 43x43:3
DjVuL reconstruct... 2 level
Save png: lena.r.png.
See demo of stbDjVuL.
The base of the algorithm was obtained in 2016 by studying the works monday2000 and adapting them to Linux. The prerequisite was the BookScanLib project and the algorithm DjVu Thresholding Binarization. This algorithm embodied good ideas, but had a recursive structure, was a "function with discontinuities" and had a hard color limit. The result of this algorithm, due to the indicated shortcomings and the absence of regulators, was doubtful. After careful study, all the foundations of the specified algorithm were rejected. The new algorithm is based on levels instead of recursion, a smooth weight function is used instead of a "discontinuous" one, no color restriction, BG/FG selection controls are enabled. The new algorithm allowed not only to obtain a much more adequate result, but also gave derivative functions: image division into BG/FG according to the existing mask.