Brownian motion

around the essentials…

 

“Tweaking” photographed text pages

This time we have this task: we need to print badly taken digital pictures, so we have to improve them in some way — raise contrast, sharpen, make them «looking better».

As always, this result can be achieved going both easy (easy-to-use) and hard (where-am-i?..) way — we will pass both.

(Surely, below is not a single algorithm to do this job.)

Contents

  1. «Easy» — graphical — way
  2. «Hard» — from a command-line
  3. Conclusion

«Easy» way

  1. Launch your favotire graphical editor and open image:
    01-open-image
    If your camera give you horizontal image, you need to rotate it, of course.
  2. Duplicate background in a new layer:
    02-duplicate-layer
  3. Blur newly created (upper) layer a lot:
    03-blur-layer
    I’ve choosen value of 20 for blur radius, but this may be increased — have a try. I’ve been using up to 250 for some particular (rather large) images.
  4. Select «Division» as a composition mode for this layer:
    04-compose-divide
    After these steps we have:
    05-composed-result
  5. Flatten image:
    06-flatten
  6. Increase sharpness using «Unsharp mask» filter:
    07-unsharp-mask
  7. Save, print, enjoy…

In a real life case we may want to use some different algorithm, different values, but… we are talking about something completely different here :-)

Keep reading.

«Hard» way

image=${1:?"Set image name as a param"}
 
# let's say all images have three-letters "extension"
 
convert -monitor $image \
        \( +clone -blur 0x20 \) +swap \
        -compose divide -composite \
        -sharpen 0x1.3 ${image%%.*}_better.${image: -3:3}

Page before and page after (downsized for web).

Btw, if your camera gives horizontal image sometimes and you need to rotate some images — some, but in the same direction — you can use key «-rotate "90>"». This will rotate only horizontal images. Well, if you camera, luckily, provide your images with orientation tag, you can use -auto-orient, of course!

Btw, again, if you need to have black colour a bit more black, you can modify a script in, let’s say, this way:

image=${1:?"Set image name as a param"}
 
convert -monitor $image \
        -rotate "90>" \
        \( +clone -blur 0x20 \) +swap \
        -compose divide -composite \
        \( +clone -blur 20 \) +swap \
        -compose multiply -composite \
        -sharpen 0x1.3 ${image%%.*}_farbetter.${image: -3:3}

Page before, after the first script, after the second one (downsized for web). Again, this is not the only way, as if working with The GIMP or PhotoShop, of course :О)

For these particular images i’ve stopped on this:

image=${1:?"Set image name as a param"}
out="002"; mkdir -p ${out}
 
convert -monitor $image \
        -resize "3456x3456>" \
        -rotate "90>" \
        -median 1 \
        \( +clone -blur 0x20 \) +swap \
        -compose divide -composite \
        \( +clone -median 3 \) +swap \
        -compose multiply -composite \
        -level 10%,90%,1 \
        -sharpen 0x1.3 ${out}/${image%%.*}.${image: -3:3}

For the last picture this gives (downsized for web):
dscf3185_probably_final

Image is quite clean, occupies less disk space, can be pretty-printed :-)

Conclusion

:-)

I hope, you’ve agreed with my sarcasm.

And needless to say how easy that «hard» way — for a single picture, for all pictures in a directory, for all images around… Btw, long live „find” :-)

Of course, in real life it’s more convenient to have all processed images in a separate directory — it’s not a problem, too.

This command-line way works great under both Linux and (almost great,-) Windows. Just download and install ImageMagick. And read the manual :-)

(No Ratings Yet)

Leave a Reply

XHTML: Можете використовувати такі теґи: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Recent Posts

Tags

Archives