Ok, so today I tried some pages with both pictures AND colored text. And, as usual, I want all the text to run through minidjvu for best quality and size. For the colored text, I tried the code given in
this post, but it didn't quite work for me. I did find a similar method that seems to be working on my files, so I thought I'd share it here. It really is the same method as in the link above, and I'm grateful to have found it or this would have taken me much longer to figure out... I just needed slightly altered processing to make it work on my files.
For simplicity, let's just focus on colored text and not the image, since it's really two issues (the image goes in the BG44 chunk of the final file just like the case when there's no colored text anyway).
So, let's look at this page. Not the greatest-looking scan, to be sure. Hopefully we'll clean it up a bit in the process. All these pictures are of course 10%-size versions so I'm not putting huge files on the forum. You should still be able to get the idea:
![expage.png](./download/file.php?id=3627&sid=058a49fdde226a3dac5b98136936b089)
- expage.png (357.31 KiB) Viewed 26386 times
... First, I use scantailor to produce a nice bitonal version, which I run through minidjvu...
![expagebw.png](./download/file.php?id=3628&sid=058a49fdde226a3dac5b98136936b089)
- expagebw.png (149.18 KiB) Viewed 26386 times
... So that's the mask layer (Sjbz) of the final product. Now we need the FG44 chunk to tell us which portion of the text should be red. I use this command:
Code: Select all
convert ${1}.tif -black-threshold 70% -white-threshold 80% -fuzz 20% -fill crimson -opaque "#F2628E" -fill black +opaque crimson -morphology DilateI:3 Octagon:3 -morphology DilateI:3 Rectangle:3x1+1+0 -morphology CloseI:3 Disk -resize 20% pt1.ppm
Let's break this command down:
- -black-threshold 70% -white-threshold 80% This just makes nearly-black pixels black and nearly-white pixels white. It helps ensure we don't accidentally think the normal text is colored text in the next step.
- -fuzz 20% -fill crimson -opaque "#F2628E" This grabs pixels that look like the input red pixels, and turns them crimson. I used a paint program to identify the input color as near #F2628E
- -fill black +opaque crimson This isolates the crimson pixels I just created and makes everything else black.
- -morphology DilateI:3 Octagon:3 -morphology DilateI:3 Rectangle:3x1+1+0 -morphology CloseI:3 Disk This fattens up the crimson areas via dilation and "closing". I read about it here: http://www.imagemagick.org/Usage/morphology/ In a perfect world this shouldn't be necessary, but if the first step didn't quite grab all the right pixels, then this acts as insurance. We'll likely have covered all the text area in crimson after this step.
- -resize 20% We don't need to do this color masking at the full DPI of the image. This saves on file size.
... maybe a '-despeckle' should be in there prior to the morphology stuff in case I still manage to grab a stray pixel or two... hmm... anyway...
The output of the above command looks like this:
![pt1.png](./download/file.php?id=3630&sid=058a49fdde226a3dac5b98136936b089)
- pt1.png (11.76 KiB) Viewed 26386 times
See how the letters are all fattened up? Perfect!
Now, we simply encode that with c44, and extract the BG44 chunk, which will be the FG44 chunk of our final product:
Code: Select all
c44 -dpi 120 -decibel 50 pt1.ppm _foreground.djvu
djvuextract.exe _foreground.djvu BG44=_foreground.iw4
NOTE Common sense says it would be good to use the inverse of the text as a mask for this step, to tell c44 that we don't need much fidelity where there isn't any text to color. However, in my (admittedly limited) tests, the mask cause the output to be all wonky and the crimson color bled into the surrounding text. I'm not sure why this happened, but at least in my case the mask did NOT help me. I may run further tests later to see if I can get that to work.
So, now we have a FG44 chunk, and minidjvu will give us the Sjbz chunk for the text itself. If there were an image on the page we'd use c44 to get a BG44 chunk... and djvumake combines it all for us:
Code: Select all
djvumake out${1}.djvu INFO=,,600 Sjbz=sepvu_txt.djvu FG44=_foreground.iw4
And it looks like this:
![output.png](./download/file.php?id=3631&sid=058a49fdde226a3dac5b98136936b089)
- output.png (361.62 KiB) Viewed 26386 times
...which in my opinion is better than the original since the colors are all very clean and deep (unlike the input I was working with).