I was initially looking at developing my own background removal algorithm but it appears that the popular document format DjVu has its own foreground / background separation functions if I can only understand how to work with it.
Quoting the DjVu docs:
DjVu has 3 basic "modes":
- DjVuText -- black and white (bitonal) documents
- DjVuPhoto -- continuous-tone images such as photos, scanned graphic art, etc.
- DjVuLayered -- color documents such as magazines, catalogs, historical documents, etc.
Compressing to DjVu with the DjVuLayered mode will produce files between 30KB and 100KB, of which 5 to 40KB will be used for the foreground layer, and the rest for the backgrounds and pictures.
And for the software integration:
DjVuLibre includes a standalone viewer, a browser plug-in (for Mozilla, Firefox, Konqueror, Netscape, Galeon, and Opera), and command line tools (decoders, encoders, utilities).
Any ideas how I can work with the DjVu tools to separate the background and foreground of a given scanned document?
If the document is scanned from a scanner then the image is just a flat bitmap like image. There are no layers or objects as such. Just pixels and more pixels. To make a DjVu into layered document it would have to be generated as a layered document.
Edited Answer:
Sorry, I was not aware. I did some research and you are right. The layering option needs to be turned on in the DjVu encoding settings though. The tells the encode to use a special image processing algorithm to search for foreground and background objects and it save them to separate layers.
http://djvu.sourceforge.net - DjViLibre is a C++ library that will do what you need.
WinDjView - http://windjview.sourceforge.net/ is a nice DjVu file viewer built on DjVuLibre. It has an option to View either Foreground or Background objects. So this would be a good way to test how good the algorithm is before digging into c++ code.
I would recommend uploading some scanned TIFF / JPEG files to http://any2djvu.djvuzone.org/ and then using WinDjView to see the results of the fore / back separation. I uploaded 1 color JPEG document and was quite impressed with the results.
Source code for WinDjView is available at http://windjview.cvs.sourceforge.net/viewvc/windjview/windjview/ - RenderThread.cpp - The function CRenderThread::Render() is the layer splitting/viewing code for the foreground/background viewing functions in WinDjView.
Also there is a PDF document explaining how the algorithm works - "A GENERAL SEGMENTATION SCHEME FOR DJVU DOCUMENT COMPRESSION ..." - If you perform a Google search with "vincent djvu segmentation" and then click on "Quick View" link of the 1st result then you can read the PDF. The original PDF is no longer available.
I will have to do some more testing myself. I wonder what the licensing fees are for commercial apps ?
I hope this answers your question a little better than my first attempt. I looked a DjVu when it first came out and overlooked this feature for some reason.
Additional Information
I uploaded about 10 more documents and have come to the following conclusions. 300dpi B/W images are not able to be processed by DjVu into fore/back layers. The whole page of a B/W converted image is contained in the foreground only. When you upload to any2djvu, it first asks you if it is a B/W or color document. When you choose B/W you lose the background processing option which supports my theory the B/W is not supported for automatic background separation. Fore/Back separation works on Gray and Colour images. I do not have enough scanned images to test how well it performs though.
The fact the B/W separation is not supported possibly points to part of the reason DjVu did not take off in the document management industry many years ago. When it first came out, most computers had a difficult enough time processing, deskewing and despeckle of B/W images. So it was not feasible to perform greyscale or color image processing and most solutions were B/W for speed reasons. If we were working with color images back then, then DjVu would have been a very good solution. DjVu at the time it was released, was not much use in scanning applications for OCR. It is a great technology though even today.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With