I wrote some code to automate the steps here.
Which are listed below:
In order to successfully add a background image to a foreground image, I have to follow these steps (using a DOS Cmd window):
1- extract the bitomal RLE image from the Djvu File
ddjvu -format=rle -v myfile.djvu temp.rle
2- extract (or create) the background image. Be sure that the size of this image is equal or greater than the foreground image in order to have, after a reduction a integer:
e.g. I have a 2592 x 3508 300dpi foreground image, and I want a background image of 100dpi. So I create a 2592] x 3510 100dpi image (I added 2 pixels to the height in order to have 2594 modulo 3=0). After a 1/3 resampling, I have a 864 x 1170 image.
3- (do something with this background image) and save it as myfile.ppm (24 bits per pixel)
4- join into an unique file the 2 images:
copy /b myfile.rle + myfile.ppm myfile.mix (using a brave old DOS command)
5- encode the new page into a DjVu file:
csepdjvu -vv -d 300 myfile.mix myNewFile.DjVu
Bingo: It works!!!