Need help with colored text and border

Don't know where to start, or stuck on a certain problem? Drop by and tell us about it. Feel like helping others? Start here.

Moderator: peterZ

Post Reply
ibr4him
Posts: 102
Joined: 18 Oct 2010, 10:36

Need help with colored text and border

Post by ibr4him »

[image removed]

This book has colored text (not much) and colored border (all pages). I played around with imagemagick commands posted here on the forum but nothing helped.

Can someone help with the imagemagick command that makes the border one solid color, preserves colored text and makes black colored text pure black, and perhaps increase the sharpness too.

I'd really appreciate any help.

Thanks a ton!
Last edited by ibr4him on 08 Jan 2012, 14:25, edited 1 time in total.
User avatar
strider1551
Posts: 126
Joined: 01 Mar 2010, 11:39
Number of books owned: 0
Location: Ohio, USA

Re: Need help with colored text and border

Post by strider1551 »

Wow... that is a challenge. The brown color is so close to the black, and is slightly lighter on the left of the image than the right.

You may not want to palletize the colors (reduce them to a limited number). Ordinarily, most people reduce their books to bitonal (black/white) for the greatly reduced filesize. A lot of finer detail in the characters is lost when doing that in the resolution ranges we work with - acceptable for most people, but looking at that script (arabic?), I don't know if you can tolerate loosing too much detail.

I gave it a shot. Keep in mind that I'm no expert at this, I just enjoy tinkering with fun problems. A cleaned up image (n.b. The tiff image is better - step_04.tif - but last I knew the forum didn't show previews of tif images):

Code: Select all

#! /bin/bash

#
# Clean up the image: sharpen, paletize some of the color
#

# Sharpen
convert -unsharp 5 "base.jpg" "base.ppm"

# Remove opposite page bleed through
convert -opaque white -fill white -fuzz 10% "base.ppm" "step_01.tif"

# Move the brown border/text closer to a uniform brown
convert -fuzz 5% -fill "#816c51" -opaque "#816c51" "step_01.tif" "step_02.tif"
convert -fuzz 1.5% -fill "#816c51" -opaque "#5a4a3b" "step_02.tif" "step_03.tif"

# Move the black text closer to a uniform black
convert -fuzz 12% -fill "black" -opaque "#1c110f" "step_03.tif" "step_04.tif"

convert step_04.tif out_cleaned.jpg
...and one that I tried to paletize. I'm not quote there yet, but you can see how much detail is lost:

Code: Select all

#! /bin/bash

#
# Clean up the image: sharpen, paletize some of the color
#

# Sharpen
convert -unsharp 5 "base.jpg" "base.ppm"

# Remove opposite page bleed through
convert -opaque white -fill white -fuzz 10% "base.jpg" "step_01.tif"

# Move the brown border/text closer to a uniform brown
convert -fuzz 5% -fill "#816c51" -opaque "#816c51" "step_01.tif" "step_02.tif"
convert -fuzz 1.5% -fill "#816c51" -opaque "#5a4a3b" "step_02.tif" "step_03.tif"

# Move the black text closer to a uniform black
convert -fuzz 12% -fill "black" -opaque "#1c110f" "step_03.tif" "step_04.tif"

convert step_04.tif out_cleaned.jpg

#
# Paletize to only brown/black
#

# Isolate black and red colors to only the sections of the image where those colors should be.
# Note that we can "loose" the shape of the characters, all we need to do is get red and black
# in the general areas.
convert -fuzz 2% +opaque "black" "step_04.tif" "_black.tif"
convert -fuzz 2% +opaque "#816c51" "step_04.tif" "_color.tif"
composite -compose multiply "_color.tif" "_black.tif" "_composite.ppm"

# Create the iw44 foreground.
convert "_composite.ppm" -threshold 50% -negate "_foreground_mask.pbm"
c44 -mask "_foreground_mask.pbm" "_composite.ppm" "_foreground.djvu"
djvuextract "_foreground.djvu" BG44="_foreground.iw4"

# Create the text layer that will be colored.
convert "base.ppm" -threshold 85% "_text.tif"
cjb2 -dpi 600 -lossy -losslevel 120 "_text.tif" "_text.djvu"

# Put it all together.
djvumake "out.djvu" INFO=,,600 Sjbz="_text.djvu" FG44="_foreground.iw4"
ddjvu -format=tiff out.djvu out.tiff
convert out.tiff out_palletized.jpg
Now that is all specific to that image. Lord only knows what would happen on other images from the same book.

Edit: I'm sure the second image could be made with imagemagick somehow instead of going through the djvulibre tools... I just already knew how to go that route.
User avatar
daniel_reetz
Posts: 2812
Joined: 03 Jun 2009, 13:56
E-book readers owned: Used to have a PRS-500
Number of books owned: 600
Country: United States
Contact:

Re: Need help with colored text and border

Post by daniel_reetz »

I removed the page images at the original poster's request, however the borders of the page, which are the subject of the original request, and the focus of Strider's excellent tutorial, are OK to post, so I am attaching them to this post.

HOWEVER, I need to emphasize that our policy, generally, is that users be respectful of other users by not posting things that need to be deleted later. It makes a mess of the forums and makes finding answers even more difficult than it already is.

Also, whenever I technically figure it out, I will be disabling editing of posts after a certain time limit.
out_palletized.jpg
out_cleaned.jpg
Post Reply