mgr's weblog

Using an Image Viewer as a Presentation Program,
Image Correction in Batch Mode (Using The GIMP)

November 27, 2008, Lisp
Last edited on November 28, 2008

As already mentioned in the German article Public Speech: History of Typesetting and Letterpress Printing I have given that speech without any slides. Instead I've made use of a simple image viewer and a LCD projector to present the eighty pictures. In this article I describe the preparations.

Color Correction of Scanned Images

Eighty pictures, and most of them I had to scan by myself from the various books that I have used. That means that the colors had to be altered a tad, at least we need to correct the input level of the colors (e.g. using The GIMP's Adjust Color Levels tool). We want well balanced images, the levels should be distributed all over the whole color range, and it'd be best if the text of the reverse side could not be seen through (remember that often book pages are quite thin).

If your picture is just composed of pen strokes (for example pencil drawings or woodcuts) it's a nice trick to propagate the lower value pixels before using the Levels tool (Filters → Distorts → Value Propagate, More Black), so that afterwards you can apply the Levels tool more harshly. This method is described quite nicely in Liam Quin's How to Clean Up Scanned Engravings and Old Photographs, (second) step 8. Strengthen Those Lines. He aptly writes: "The point of this is that when you make the image brighter the edges of the dark lines get eaten away, so you need to strengthen them first."

Automate the Color Correction

We certainly do not want to do this for some dozen images! Luckily The GIMP has a nice batch mode to automate this process. At the same time it is (in my opinion) a bit easier to write a batch script instead of a filter script that is embedded into The GIMP with a special dialog box (though that is not that hard, either).

How this is done is described in the compact tutorial GIMP Batch Mode. Thank you, anonymous writer, for having written that nice page! Remember to consult The GIMP's helpful Procedure Browser, (GIMP toolbox → Xtns → Procedure Browser) when writing your own scripts. It gives you a list of all commands and describes all their parameters in detail (although, sadly, it describes not everything you need to know…). Here is my script:

(define (batch-vpropagate-levels pattern)
  (let∗ ((filelist (cadr (file-glob pattern 1))))
    (while (not (null? filelist))
           (let∗ ((filename (car filelist))
                  (image (car (gimp-file-load RUN-NONINTERACTIVE
                                              filename filename)))
                  (drawable (car (gimp-image-get-active-layer image))))
 
             (plug-in-vpropagate RUN-NONINTERACTIVE
                                 image drawable
                                 1 ;; more black
                                 1 ;; channel
                                 0.18 ;; rate
                                 15 ;; direction mask
                                 0 ;; lower-limit
                                 255 ;; upper-limit
                                 )
             (gimp-levels drawable
                          0 ;; value channel
                          125 242
                          1.5
                          0 255)
 
             (gimp-file-save RUN-NONINTERACTIVE
                             image drawable filename filename)
             (gimp-image-delete image))
           (set! filelist (cdr filelist)))))
 
(define (batch-levels pattern)
  (let∗ ((filelist (cadr (file-glob pattern 1))))
    (while (not (null? filelist))
           (let∗ ((filename (car filelist))
                  (image (car (gimp-file-load RUN-NONINTERACTIVE
                                              filename filename)))
                  (drawable (car (gimp-image-get-active-layer image))))
 
             (gimp-levels drawable
                          0 ;; value channel
                          75 245
                          1.0
                          0 255)
 
             (gimp-file-save RUN-NONINTERACTIVE
                             image drawable filename filename)
             (gimp-image-delete image))
           (set! filelist (cdr filelist)))))

Save it to a file named adjust-scan.scm in the directory ~/.gimp-2.x/scripts/. The first function is an example script for line drawings; the second one is the function that I've used for all scanned images of said speech.

I wanted a quick'n'dirty solution, so I've just determined reasonable values using one or two images. Of course, we have to scan all images with the same scanning settings! Then I have copied all original images to a new directory—as the functions change the images in place—, and fired up:

gimp -i -b '(batch-levels "∗.png")' -b '(gimp-quit 0)'

Hint

If you want to get small files—e.g. for the Web or to have them included in a PDF document—select the input level range more rigorously in order to remove the noise of the paper texture, convert the image to indexed colors with a color map of twenty to fifty colors (Image → Mode → Indexed…, important: select Generate optimum palette), and save it as a PNG file.

Sorting the Images

Now I've put all images—the scanned and post-processed ones as well as selected images from the Web—in a new directory called Selection. I've generated a list of all image files using the command:

ls -1 > files

Open it and sort the files as you need them during your speech. Prepend whatever you want to lines of files that you do not need after all and insert blank lines as you want. Create a subdirectory Sorted and call this BASH script:

IFS=$'\n';
num=1;
for i in $(<files);do
    # echo $i | grep "__handiwork\."
    handifile=${i:0:${#i}-4}__handiwork${i: -4}
    ls $handifile >/dev/null 2>&1
    if [ $? -eq 0 ] ; then
        i=$handifile
    fi
    newname=$(printf "%03d" $num)__$i; 
    echo $newname; 
    cp -l $i Sorted/$newname ;
    let num=$num+1;
done

It generates numbered hard links in the subdirectory to all files that you have listed in the file files. If you need to manually adjust an image append "__handiwork" to its file name just before the (three letter) extension; it will be selected instead of the original file.

A nice thing about this solution is the fact that it is independent of the particular image viewer program, as long as it can show images in the alphabetical order of their file names. If your notebook has a problem just before your speech, it is more easy to use another person's computer: even Microsoft Windows's built-in picture preview, the Picture and Fax Viewer, is enough.


Please send me an email if you liked this article! You even do not need to mention the colour of your socks and/or include a picture of your ankles, as Liam Quin asks you to do! :-)

Trackback pings for this entry are listed below. The URL to ping for this entry is: https://blog.matroid.org:443/trackback/62

Select a Theme:

Basilique du Sacré-Cœur de Montmartre (Paris) Parc Floral de Paris Castillo de Santa Barbara (Alicante) About the photos

Entries: