Bitonal conversion using Photoshop (Gimp & Imagemagic...)

Share your software workflow. Write up your tips and tricks on how to scan, digitize, OCR, and bind ebooks.

Moderator: peterZ

xorpt
Posts: 42
Joined: 24 Feb 2012, 01:37
E-book readers owned: Sony PRS-T1
Number of books owned: 2000

Bitonal conversion using Photoshop (Gimp & Imagemagic...)

Post by xorpt »

I'd like to share with you the results of long hours of research... :mrgreen: :geek: I hope you Photoshop experts can suggest me new ways!

Background

I use ScanTailor for processing my scans. Although I find it very efficient to split pages, deskew and set margins around contents, sometimes I am frustrated by the bitonal output. It is usually good (or very good 8-) ), especially on standard alphabetic text, but for text containing smaller details, or for other languages, it can be far from satisfactory.

I scan a lot of japanese text for my own language study, and I need to be able to read it on my ereader. Using a grayscale instead of bitonal gives very clean characters, but there are two drawbacks: larger PDF files (no DJVU), and less contrast on the eInk (actually not readable, in my opinion).

Bitonal conversion using ScanTailor

Here is an example of japanese output from ST, using setting "0"

Image

Scan Tailor using "Thinner -20"

Image

As you can see in the first image some of the characters are too thick. If you try to lighten the output it improves a little bit, but the other characters tend to disappear. Note that I get slightly better results using ABBYY Finereader, but not significantly better...

Bitonal conversion using Photoshop

1. First, output the page from Scan Tailor using the color / grayscale output

Image

2. Image > Mode > Grayscale
3. Image > Adjustments > Levels. Remove as much as possible from the background (or you will get speckles...) and increase contrast as much as possible without loosing too much details.

Image

4. Select Background Layer > Duplicate Layer
5. Select New layer -> Filter > Sketch > Photocopy. Use Detail = 1, Darkness = 50. The "photocopy" filter nicely draws the edges of each character. Drawback: it leaves the center white :cry:

Image

6. Select New layer -> Filter > Blur > Gaussian Blur. Use 0.5 to 1 (here 0.6). The "photocopy" filter's output is crenelated, so we can limit that a little by adding Gaussian blur. You can try different values, to get the best compromise between details and smoothness.

Image

7. Select New layer -> Change "Fill" to 70%. This will show the Background layer through the new layer, allowing to fill the inside of the characters, that the "photocopy" filter messed up.

Image

8. New adjustement layer > Threshold. Value = 190. This converts to bitonal

Image

compared with ST:

Image

As you can see the result is not as smooth as ST, but with much more details. In my experience, this is not a problem since the PDF viewer will correct that. On a ereader the characters are quite smooth, no problem to read... and very contrasty

If you have better ideas, please share ;)
Last edited by xorpt on 25 Apr 2012, 05:11, edited 3 times in total.
xorpt
Posts: 42
Joined: 24 Feb 2012, 01:37
E-book readers owned: Sony PRS-T1
Number of books owned: 2000

Re: Bitonal conversion using photoshop

Post by xorpt »

Bitonal conversion using The Gimp

I am not a Gimp expert (nor a Photoshop one BTW :P ) and I have not played enough with Gimp to give a complete Tutorial yet, but I think you can achieve very similar results by using the following procedure:

1. Export in Color / Grayscale from ScanTailor and open in Gimp
2. Image > Mode > Grayscale
3. Colors > Levels (remove the background (put the white arrow on the left of the levels' peak that represents the background) and increase contrast (black and middle arrow to the right)
4. Duplicate Background layer
5. On layer "Background copy": Filters > Edge-detect > Difference of Gaussians. Play with values... for example Radius 1: 6, Radius 2: 1
6. On layer "Background copy": Filters > Blur > Gaussian Blur. Play with values... for example Horizontal: 1, Vertical: 1
7. On layer "Background copy": set Opacity: 70%
8. On layer "Background copy": Colors > Threshold. Play with the cursor. You should see the best results in the 240-255 interval
9. Flatten image
10. Colors > Threshold

Image

Gimp looks very promising... if only I knew how to use it correctly... and I have to learn to do batch jobs :oops:
xorpt
Posts: 42
Joined: 24 Feb 2012, 01:37
E-book readers owned: Sony PRS-T1
Number of books owned: 2000

Re: Bitonal conversion using Photoshop (and the Gimp...)

Post by xorpt »

Bitonal conversion using Imagemagick

I'm now trying to get the same results using Imagemacgick. I'm not completely satisfied by the results, but it already looks not so bad. Unfortunately the processing time in batch is a little slower than with Photoshop (I think).

To use:

1. copy the following code in a text file

Code: Select all

@ECHO off
FOR %%1 in (*.tif) DO (
convert %%1 -colorspace gray -level 40,160,0.67 "%%~ndp1_layer1%%~x1"
convert "%%~ndp1_layer1%%~x1" -negate -edge 1 -negate -gaussian-blur 0.8 "%%~ndp1_layer2%%~x1"
composite -dissolve 70 "%%~ndp1_layer2%%~x1" "%%~ndp1_layer1%%~x1" "%%~ndp1_comp%%~x1"
convert "%%~ndp1_comp%%~x1" -threshold 81%% "%%~ndp1_final.png"
del "%%~ndp1_layer2%%~x1" "%%~ndp1_layer1%%~x1" "%%~ndp1_comp%%~x1"
)
2. rename the file in .bat
3. copy the .bat file to the directory containing the images
4. double-click to launch

Image

Since there are some IM experts here, maybe someone could suggest a way to optimize this?
xorpt
Posts: 42
Joined: 24 Feb 2012, 01:37
E-book readers owned: Sony PRS-T1
Number of books owned: 2000

Re: Bitonal conversion using Photoshop (Gimp & Imagemagic...

Post by xorpt »

OK, OK, one must learn... I just found out that all my clumsy IM commands above can be summarized in ONE single convert command. So please replace 1. above by:

Code: Select all

FOR %%1 in (*.tif) DO (
convert %%1 -colorspace gray -level 40,160,0.67 ^( +clone -negate -edge 3 -negate -gaussian-blur 1 ^) -compose dissolve -define compose:args=70 -composite -threshold 81%%  "%%~ndp1_final.png" 
)
The code looks nicer, and it's also quicker :). But the output is still the same, and I must find a way to make it a little smoother :evil: i'll keep you updated (not that I sense so much enthusiasm though... :mrgreen: )

Edit: I have got a better output using -edge 3, so I changed this parameter in the script. Here is the result:

-edge 3: thicker so more readible, with less details

Image

-edge 2: more details, maybe the best compromise

Image
User avatar
Gerard
Posts: 154
Joined: 17 Oct 2010, 07:15
Number of books owned: 0
Location: Berlin (Germany)

Re: Bitonal conversion using Photoshop (Gimp & Imagemagic...

Post by Gerard »

You could up scale the images and after processing down scale this could result in a smoother edge

an other idea is:
this is the result of inkscape (trace bitmap) Vectorization
path3054-1.png
path3054-1.png (84.54 KiB) Viewed 28562 times
(i took this images as input)
6117c4fb647489b4c5b58b42c51317b057b1cd44.png
6117c4fb647489b4c5b58b42c51317b057b1cd44.png (13.51 KiB) Viewed 28562 times
inkscape uses potrace http://potrace.sourceforge.net/
xorpt
Posts: 42
Joined: 24 Feb 2012, 01:37
E-book readers owned: Sony PRS-T1
Number of books owned: 2000

Re: Bitonal conversion using Photoshop (Gimp & Imagemagic...

Post by xorpt »

Very nice!!! :) Thanks a lot, I like what I see!

I'm going to try that.

Imagemagick has a vectorization module also ... I'm going to try it also...
Edit: actually they recommend using Autotrace or PoTrace...
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: Bitonal conversion using Photoshop (Gimp & Imagemagic...

Post by daniel_reetz »

Thanks, xorpt, for putting together this valuable tutorial and thanks, Gerard, for the pointer!
xorpt
Posts: 42
Joined: 24 Feb 2012, 01:37
E-book readers owned: Sony PRS-T1
Number of books owned: 2000

Re: Bitonal conversion using Photoshop (Gimp & Imagemagic...

Post by xorpt »

Thanks!

I have experimented with potrace, which gives very good results, provided the input is clean, with clearly delimited lines.

The last book I converted was done using the following workflow:

1. Rename files with Ant Renamer
2. Merge the files in one directory
3. Use Scan Tailor to deskew, select contents, add margins. Export to Color, White margins, Equalize illumination.
4. In the out directory add a .bat file with the following (* note: this script will work with the latest versions of ImageMagick only)

Code: Select all

FOR %%1 in (*.tif) DO (
convert %%1 -colorspace Gray -level 20%%,80%%,.67 ^( +clone -bias 50%% -morphology convolve DoG:1,0,1 -level 0%%,50%%,.45 ^) -compose dissolve -define compose:args=70 -composite -threshold 80%% "%%~ndp1_dog.pnm"
potrace -3 -b pgm "%%~ndp1_dog.pnm"
del "%%~ndp1_dog.pnm"
)
5. After conversion, combine files in a DJVU file with Djvu Solo.

The -morphology convolve DoG is very good a tracing edges. I will try and experiment more with other methods...
xorpt
Posts: 42
Joined: 24 Feb 2012, 01:37
E-book readers owned: Sony PRS-T1
Number of books owned: 2000

Re: Bitonal conversion using Photoshop (Gimp & Imagemagic...

Post by xorpt »

Hi all, I have spent some time learning how to use script-fu with Gimp to batch process file, and I'm happy to introduce you to the

Bitonal converter for Gimp v. 0.1

I think Gimp gives the best results I have got so far, using the difference of gaussian method of edge detection. I think that its output can be used with or without using potrace. The integration of the script-fu in GIMP is also an advantage, because you can "preview" the results on several images before applying the batch. It's not exceptionally quick but it's not so bad either.

This plug-in has two parts:

- "Bitonal converter" is a test filter, that can be used on an open image to play with the parameters and test the results. This is meant to prepare the correct parameters to use in the batch processing
- "Batch bitonal converter" takes a folder and file extension in input and applies the filter to all corresponding files.

Tested with Gimp 2.6 on Windows XP (should work with later versions and other O.S. - waiting for your feedback)

How to install the scripts:

Download the .scm files and put them in "<GIMP install directory>\share\gimp\2.0\scripts". You should see the scripts appear under the "Filters" menu. If Gimp is already opened, use "Filters > Script-Fu > Refresh Scripts".
gimp-bitonal-converter.zip
Download the files
(1.75 KiB) Downloaded 1074 times
How to use "Bitonal converter":

Image

Note: the script works best on images exported from ScanTailor in Color/Grayscale mode with "Equalize illumination".

1. Open an image (Note: the image must be in RGB mode)
2. Go to "Filters > DIY Book Scanning > Bitonal converter
3. Change parameters
4. Click OK

You can cancel the filter effects using Ctrl+Z, re-open it and try other parameters.
The most important parameters to play with are:

- Level White: try to remove as much background as possible without loosing details on the characters, using the lowest value giving a good result
- Gaussian Horizontal / Gaussian Vertical: this adds blur to smoothen the characters' edges. Higher values give more rounded edges and thicker characters but less details
- Opacity & Thresholds: if you get some white filling inside the characters, try lowering the Opacity value. Change the thresholds if the characters are too thin or too thick

How to use "Batch bitonal converter":

Image

Note: the script works best on images exported from ScanTailor in Color/Grayscale mode with "Equalize illumination".

1. Go to "Filters > DIY Book Scanning > Batch bitonal converter (you need to have an image opened or to do "Refresh Scripts" to have the menu option activated)
2. Choose the directory containing the images to be processed (WARNING: all images with the indicated extension will be processed!)
3. Change parameters
4. Click OK

The original files are kept. New files are created with the suffix "_".

To do: add some exceptions & error handling, renaming options, output formats.

The code:

bitonal-converter

Code: Select all

(define (bitonal-converter inImg Drawable lvlb lvlw lvlg dog1 dog2 gaus1 gaus2 opac thresh1 thresh2)
	(gimp-image-undo-group-start inImg)
	(gimp-image-convert-grayscale inImg)
	(gimp-levels Drawable 0 lvlb lvlw lvlg 0 255)
	(let* (
			(dog-layer (car (gimp-layer-copy Drawable 0)))
		)
		(gimp-image-add-layer inImg dog-layer -1)
		(gimp-layer-set-name dog-layer "dog")
		(plug-in-dog RUN-NONINTERACTIVE inImg dog-layer dog1 dog2 TRUE TRUE)
		(plug-in-gauss RUN-NONINTERACTIVE inImg dog-layer gaus1 gaus2 1)
		(gimp-layer-set-opacity dog-layer opac)
		(gimp-threshold dog-layer thresh1 255)
	)
	(gimp-image-flatten inImg)
	(let* (
			(Drawable (car (gimp-image-get-active-layer inImg)))
		)
		(gimp-threshold Drawable thresh2 255)
	)
	(gimp-displays-flush)
	(gimp-image-undo-group-end inImg)
)

(script-fu-register "bitonal-converter"
                    "Bitonal converter"
                    "Bitonal conversion for DIY scanners using DoG"
                    "Timothee Lecaudey"
                    "Timothee Lecaudey"
                    "2012-05-06"
                    "RGB*, GRAY*"
                    SF-IMAGE "Input Image" 0
                    SF-DRAWABLE "Input Drawable" 0
					SF-ADJUSTMENT "Level Black" '(20 0 255 1 1 0 0)  
					SF-ADJUSTMENT "Level White" '(220 0 255 1 1 0 0)  
					SF-ADJUSTMENT "Level Gamma" '(0.67 0 1 0.01 0.01 2 0) 
					SF-ADJUSTMENT "DoG radius 1" '(6 0 10 0.5 0.5 1 0)
					SF-ADJUSTMENT "DoG radius 2" '(1 0 10 0.5 0.5 1 0)
					SF-ADJUSTMENT "Gaussian Horizontal" '(1 0 10 0.1 0.1 1 0)
					SF-ADJUSTMENT "Gaussian Vertical" '(1 0 10 0.1 0.1 1 0)
					SF-ADJUSTMENT "Layer Opacity" '(70 0 100 0.5 0.5 1 0)
					SF-ADJUSTMENT "First threshold" '(240 0 255 0.5 0.5 1 0)
					SF-ADJUSTMENT "Second threshold" '(160 0 255 0.5 0.5 1 0)
					)
(script-fu-menu-register "bitonal-converter"
                          "<Image>/Filters/DIY Book Scanning")
bitonal-converter-batch

Code: Select all

(define (bitonal-converter-batch filepath file-extension lvlb lvlw lvlg dog1 dog2 gaus1 gaus2 opac thresh1 thresh2)
	(let* 
		(
			(filelist (cadr (file-glob (string-append filepath DIR-SEPARATOR "*." file-extension) 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-image-undo-group-start image)
					(gimp-image-convert-grayscale image)
					(gimp-levels drawable 0 lvlb lvlw lvlg 0 255)
					(let* 
						(
							(dog-layer (car (gimp-layer-copy drawable 0)))
						)
						(gimp-image-add-layer image dog-layer -1)
						(gimp-layer-set-name dog-layer "dog")
						(plug-in-dog RUN-NONINTERACTIVE image dog-layer dog1 dog2 TRUE TRUE)
						(plug-in-gauss RUN-NONINTERACTIVE image dog-layer gaus1 gaus2 1)
						(gimp-layer-set-opacity dog-layer opac)
						(gimp-threshold dog-layer thresh1 255)
					)
					(gimp-image-flatten image)
					(let* 
						(
							(drawable (car (gimp-image-get-active-layer image)))
						)
						(gimp-threshold drawable thresh2 255)
						(gimp-displays-flush)
						(gimp-image-undo-group-end image)
						(gimp-file-save RUN-NONINTERACTIVE 
							image drawable 	(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1))) 
											(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1)))
						)
						
					)
					(gimp-image-delete image)
			)
			(set! filelist (cdr filelist))
		)
	)
)
(script-fu-register "bitonal-converter-batch"
                    "Batch Bitonal converter"
                    "Batch Bitonal conversion for DIY scanners using DoG"
                    "Timothee Lecaudey"
                    "Timothee Lecaudey"
                    "2012-05-06"
                    "RGB*, GRAY*"
					SF-DIRNAME "Folder" "C:\\"
					SF-STRING "File type (use * for all types)" "tif"
					SF-ADJUSTMENT "Level Black" '(20 0 255 1 1 0 0)  
					SF-ADJUSTMENT "Level White" '(220 0 255 1 1 0 0)  
					SF-ADJUSTMENT "Level Gamma" '(0.67 0 1 0.01 0.01 2 0) 
					SF-ADJUSTMENT "DoG radius 1" '(6 0 10 0.5 0.5 1 0)
					SF-ADJUSTMENT "DoG radius 2" '(1 0 10 0.5 0.5 1 0)
					SF-ADJUSTMENT "Gaussian Horizontal" '(1 0 10 0.1 0.1 1 0)
					SF-ADJUSTMENT "Gaussian Vertical" '(1 0 10 0.1 0.1 1 0)
					SF-ADJUSTMENT "Layer Opacity" '(70 0 100 0.5 0.5 1 0)
					SF-ADJUSTMENT "First threshold" '(240 0 255 0.5 0.5 1 0)
					SF-ADJUSTMENT "Second threshold" '(160 0 255 0.5 0.5 1 0)
					)
(script-fu-menu-register "bitonal-converter-batch"
                          "<Image>/Filters/DIY Book Scanning")
xorpt
Posts: 42
Joined: 24 Feb 2012, 01:37
E-book readers owned: Sony PRS-T1
Number of books owned: 2000

Re: Bitonal conversion using Photoshop (Gimp & Imagemagic...

Post by xorpt »

Bitonal converter for Gimp v. 0.2

change log:
- merged both functions in one .scm file
- drop-down list for input file types
- drop-down list for output file types
- use proper output saving procedure for each output format (gives smaller files)
- cosmetic changes
- handle images already in grayscale mode
gimp-bitonal-converter-v.0.2.zip
Download the file
(1.44 KiB) Downloaded 932 times
Code:

Code: Select all

; Batch Bitonal converter v.0.2
;
; change log:
; - merged both functions in one .scm file
; - drop-down list for input file types
; - drop-down list for output file types
; - use proper output saving procedure for each output format
; - cosmetic changes
; - handle images already in grayscale mode

(define (bitonal-converter image drawable lvlb lvlw lvlg dog1 dog2 gaus1 gaus2 opac thresh1 thresh2)
	(gimp-image-undo-group-start image)
	(if (= (car (gimp-drawable-is-gray drawable)) FALSE)
		(gimp-image-convert-grayscale image)
	)
	(gimp-levels drawable 0 lvlb lvlw lvlg 0 255)
	(let* (
			(dog-layer (car (gimp-layer-copy drawable 0)))
		)
		(gimp-image-add-layer image dog-layer -1)
		(gimp-layer-set-name dog-layer "dog")
		(plug-in-dog RUN-NONINTERACTIVE image dog-layer dog1 dog2 TRUE TRUE)
		(plug-in-gauss RUN-NONINTERACTIVE image dog-layer gaus1 gaus2 1)
		(gimp-layer-set-opacity dog-layer opac)
		(gimp-threshold dog-layer thresh1 255)
	)
	(gimp-image-flatten image)
	(let* (
			(drawable (car (gimp-image-get-active-layer image)))
		)
		(gimp-threshold drawable thresh2 255)
	)
	(gimp-displays-flush)
	(gimp-image-undo-group-end image)
)

(script-fu-register "bitonal-converter"
                    "Bitonal converter v.0.2"
                    "Bitonal conversion for DIY scanners using DoG"
                    "Timothee Lecaudey"
                    "Timothee Lecaudey"
                    "2012-05-06"
                    "RGB*, GRAY*"
                    SF-IMAGE "Input Image" 0
                    SF-DRAWABLE "Input drawable" 0
					SF-ADJUSTMENT "Levels Black" '(20 0 255 1 1 0 0)  
					SF-ADJUSTMENT "Levels White" '(220 0 255 1 1 0 0)  
					SF-ADJUSTMENT "Levels Gamma" '(0.67 0 1 0.01 0.01 2 0) 
					SF-ADJUSTMENT "DoG radius 1" '(6 0 10 0.5 0.5 1 0)
					SF-ADJUSTMENT "DoG radius 2" '(1 0 10 0.5 0.5 1 0)
					SF-ADJUSTMENT "Gaussian Blur Horizontal" '(1 0 10 0.1 0.1 1 0)
					SF-ADJUSTMENT "Gaussian Blur Vertical" '(1 0 10 0.1 0.1 1 0)
					SF-ADJUSTMENT "Layer Opacity" '(70 0 100 0.5 0.5 1 0)
					SF-ADJUSTMENT "First threshold" '(240 0 255 0.5 0.5 1 0)
					SF-ADJUSTMENT "Second threshold" '(160 0 255 0.5 0.5 1 0)
					)
(script-fu-menu-register "bitonal-converter"
                          "<Image>/Filters/DIY Book Scanning")

(define (bitonal-converter-batch filepath inType outType lvlb lvlw lvlg dog1 dog2 gaus1 gaus2 opac thresh1 thresh2)
	(let* 
		(
			(inExt
				(cond 
					(( equal? inType 0 ) "[tT][iI][fF]" )
					(( equal? inType 1 ) "[jJ][pP][gG]" )
					(( equal? inType 2 ) "[bB][mM][pP]" )
					(( equal? inType 3 ) "[pP][nN][gG]" )
				)
			)
			(filelist (cadr (file-glob (string-append filepath DIR-SEPARATOR "*." inExt) 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)))
				)
				(bitonal-converter image drawable lvlb lvlw lvlg dog1 dog2 gaus1 gaus2 opac thresh1 thresh2)
				(let* 
					(
						(drawable (car (gimp-image-get-active-layer image)))
					)
					(cond 
						((equal? outType 0 )
							(file-tiff-save RUN-NONINTERACTIVE 
								image drawable 	(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1) (- (string-length filename) 4)) ".tif") 
												(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1) (- (string-length filename) 4)) ".tif") 1
							)
						)
						((equal? outType 1 )
							(file-png-save-defaults RUN-NONINTERACTIVE 
								image drawable 	(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1) (- (string-length filename) 4)) ".png") 
												(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1) (- (string-length filename) 4)) ".png")
							)
						)
						((equal? outType 2 )
							(file-gif-save RUN-NONINTERACTIVE 
								image drawable 	(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1) (- (string-length filename) 4)) ".gif") 
												(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1) (- (string-length filename) 4)) ".gif") 0 0 0 0
							)
						)
						((equal? outType 3 )
							(file-pbm-save RUN-NONINTERACTIVE 
								image drawable 	(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1) (- (string-length filename) 4)) ".pbm") 
												(string-append filepath DIR-SEPARATOR "_" (substring filename (+ (string-length filepath) 1) (- (string-length filename) 4)) ".pbm") 1
							)
						)
					)
				)
				(gimp-image-delete image)
			)
			(set! filelist (cdr filelist))
		)
	)
)
(script-fu-register "bitonal-converter-batch"
                    "Batch Bitonal converter v.0.2"
                    "Batch Bitonal conversion for DIY scanners using DoG"
                    "Timothee Lecaudey"
                    "Timothee Lecaudey"
                    "2012-05-07"
                    "RGB*, GRAY*"
					SF-DIRNAME "Input Folder" "C:\\"
					SF-OPTION "Input Type" (list ".tif" ".jpg" ".bmp" ".png") 
					SF-OPTION "Output Type" (list ".tif" ".png" ".gif" ".pbm")
					SF-ADJUSTMENT "Levels Black" '(20 0 255 1 1 0 0)  
					SF-ADJUSTMENT "Levels White" '(220 0 255 1 1 0 0)  
					SF-ADJUSTMENT "Levels Gamma" '(0.67 0 1 0.01 0.01 2 0) 
					SF-ADJUSTMENT "DoG radius 1" '(6 0 10 0.5 0.5 1 0)
					SF-ADJUSTMENT "DoG radius 2" '(1 0 10 0.5 0.5 1 0)
					SF-ADJUSTMENT "Gaussian Blur Horizontal" '(1 0 10 0.1 0.1 1 0)
					SF-ADJUSTMENT "Gaussian Blur Vertical" '(1 0 10 0.1 0.1 1 0)
					SF-ADJUSTMENT "Layer Opacity" '(70 0 100 0.5 0.5 1 0)
					SF-ADJUSTMENT "First threshold" '(240 0 255 0.5 0.5 1 0)
					SF-ADJUSTMENT "Second threshold" '(160 0 255 0.5 0.5 1 0)
					)
(script-fu-menu-register "bitonal-converter-batch"
                          "<Image>/Filters/DIY Book Scanning")
I am now experimenting with GMIC: http://gmic.sourceforge.net/gimp.shtml

Looks like "Lylejk's stencil" could give good results to make characters smoother without using vectorization. Not sure yet on how to use it in a script-fu though... :?
Post Reply