ppmunwarp as modified by royeven (http://diybookscanner.org/forum/viewtop ... 795#p15975)
(UFRaw and GIMP are optional)
What the script does:
Color correction with a gray card either manually with UFRaw and UFRaw-batch or automatically with imagemagick. (or turned off entirely)
Geometry correction and cropping using ppmunwarp as modified by royeven (http://diybookscanner.org/forum/viewtop ... 795#p15975)
Automatic DPI calculation using ppmunwarp and royeven's new -mul option, or manual DPI entry with GIMP
Imagemagick creates final images ready for Scantailor.
In the following example, I show the steps in the automatic modes using jpg inputs, as that is, I expect, a preferred choice for most camera wielders. In my description, I will refer to the "input-format" rather than JPG, since that is a variable that the user should set for their own workflow. Images here are resized and compressed to save bandwidth, but the necessary points should be clear. (Compressed far too much...)
1. Color Correction
The script looks for the gray card calibration image, which is named in relation to user-defined variables in the script (default: color.input-format) Imagemagick crops a box, centered in the image, of an user-defined size (default, 500x500) to elminate all non-gray card areas: Imagemagick then determines the average RGB values of this small box and calculates the necessary transformations to reach the target value of the gray card (defined in script variables). These transformations are applied to all files of the user-defined input format contained in the directory. Also, at this stage, the input format is converted into ppm files that ppmunwarp can use.
2. Geometry Correction
Using a calibration image for ppmunwarp (also user-defined file name -- default is calibration.input-format), ppmunwarp will determine the lens and perspective distortions. The size of the calibration image provides crop information. (So make your calibration image a bit bigger than the book!) Using the calibration data, ppmunwarp will apply the necessary geometry fixes to all ppm files in the directory. During this stage, the images are also cropped. 3. DPI Calculation
In automatic mode, ppmunwarp will recalibrate itself on the now-corrected calibration image. It determines the average distance between calibration points. (For the points that are not detected, ppmunwarp will estimate the position of undetected dots) Using the -mul option (configurable), ppmunwarp will multiply the average distance by the user-supplied multiplier to determine DPI.
In manual mode, the image will be opened in GIMP, and, using the measuring tool and math, the user will input the correct DPI.
(Additionally, there is a mode that uses the autodetect, but allows the user to double-check)
4. Final steps
Imagemagick converts the fixed ppm files into the output format of the user's choice. (default is lzw compressed tif files) Using the DPI determined in step three, imagemagick also saves DPI information into the images. (Saving that step in Scantailor)
The script deletes intermediate files.
Here's the camera photo. There is quite a bit of lens distortion and some obvious keystoning. (Kind of fun to misaim the cameras for an example...) After color correction, geometry correction, and cropping, the final image looks much better: After running the image through Scantailor, here is an example of the result: Here is the log file:
Code: Select all
Your camera images are now being prepared for Scantailor Determining RGB values of color.JPG... Detected RGB values are 151, 146, 152 RGB values to be adjusted by 1.0728476821, 1.1095890410, 1.0526315789 Running Imagemagick to adjust colors and convert JPG to ppm... done Calculating geometry calibration data from image: calibration.ppm Number of detected points: 1938 Average: 64.829646, calculated from 1900 of 1900 data points. PPI: 329 Deskewed picture size: 3358 x 2518 (83.98% x 83.98%) done Correcting geometry. This will take some time... done Calculating DPI from image: calibration_corrected.ppm Number of detected points: 1938 Average: 64.579329, calculated from 1900 of 1900 data points. PPI: 328 Deskewed picture size: 3355 x 2516 (99.91% x 99.93%) Calculated PPI is: 328 ImageMagick will now prepare images for Scantailor... done Deleting temporary files... done Your images are ready for Scantailor
I apologize for the badly compressed images. A 75% jpg quality is obviously not enough... And yes, my lighting is poor and there are a lot of reflections in my old New Standard. It used to be better, but it involved a behemouth black shroud that was just too massive for the living room. I'm trying to save up to get one of Dan's new kits which would also solve the reflection problems. At least the software workflow is ready for that day!!