Preprocessing RAW images for Scantailor

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

Moderator: peterZ

abmartin
Posts: 79
Joined: 15 Sep 2010, 15:33
Number of books owned: 2000
Country: USA
Location: Ohio

Re: Preprocessing RAW images for Scantailor

Post by abmartin »

When you get that stream of GIMP error messages, it still opens and lets you measure? Then you had to press enter to keep going? If so, can you type the correct DPI (if needed) before pressing enter?

The errors I see in the most current log are just distro specific errors in the Lubuntu skin. I suspect that error will happen any time you open a GTK-2 application. (grrr...that's a problem. It seems to be something the devs know about, since I found that error in the bugtracker of a few lubuntu packages that use a GTK interface.) I suspect there's just a missing package or two that could be installed to solve it. Perhaps lubuntu-artwork would contain it. (Since I'm on Debian, I can't do a DPKG search for the missing images...) Google shows me that the null.png file is in that package.

$sudo apt-get install lubuntu-artwork
abmartin
Posts: 79
Joined: 15 Sep 2010, 15:33
Number of books owned: 2000
Country: USA
Location: Ohio

Re: Preprocessing RAW images for Scantailor

Post by abmartin »

Royevan,

Thanks for that description of your method. I think that's a pretty clever way of dealing with the gaps! The only other ways I can theorize to do that are very much beyond my current math abilities. I too am interested to see if an c++ guru has any improvements.

The 1 pixel differences went both ways, so it's not the fault of the method. And it was exactly right about half the time in my limited test run. The differences could have just been me not measuring properly in GIMP. (it's not hard to get off by a pixel even when zoomed It could also just be down to how gimp or ppmunwarp rounded things. As you say, it sure seems good enough.


I'll incorporate your latest fix and post a new file soon. I'm thinking about adding a configuration option for the Gimp check step. For those who are happy with the auto-detection, getting rid of a keystroke would be handy.
pablitoclavito
Posts: 39
Joined: 12 Sep 2012, 16:54
E-book readers owned: Iliad
Number of books owned: 200
Country: Spain

Re: Preprocessing RAW images for Scantailor

Post by pablitoclavito »

abmartin wrote: $sudo apt-get install lubuntu-artwork
It didn't solve the errors, but I think you're right, it is something like that.

royeven, I sent you a message, but it is in my outbox, not in sent ?? maybe it changes when you log back in...
abmartin
Posts: 79
Joined: 15 Sep 2010, 15:33
Number of books owned: 2000
Country: USA
Location: Ohio

Re: Preprocessing RAW images for Scantailor

Post by abmartin »

If you want to see what package contains the missing files, run a dpkg search

dpkg -S '/usr/share/themes/Lubuntu-default/gtk-2.0/images/null.png'

Change what is inside the single quotes to what each of the other errors say can't be found. That should tell you if there is a package that contains what you need. Install that package. It may take a logout and a login to relead the theme.
abmartin
Posts: 79
Joined: 15 Sep 2010, 15:33
Number of books owned: 2000
Country: USA
Location: Ohio

Re: Preprocessing RAW images for Scantailor

Post by abmartin »

Here's a new version. I have included royeven's fix in the checking DPI section.

Code: Select all

#!/bin/bash

###Scantailor Preprocessor###
#Fixes color with a gray card and geometry with ppmunwarp and a calibration grid
#Dependencies: Imagemagick, ppmunwarp as modified by royeven, Ufraw (only needed for RAW), Ufraw-batch (only needed for RAW), GIMP (if manual DPI calculation is desired)
#Written by abmartin and royeven at www.diybookscanner.org

###Configuration###

# Global "variables"
INPUT_FORMAT="JPG" #Change as appropriate
OUTPUT_FORMAT="ppm" #Do not change
COLOR_IMAGE="color" # The file name (without extension) of the gray card photo
CALIBRATION_IMAGE="calibration" # The file name (without extension) of the geometry calibration file
CONTROL_IMAGE="check" # The name of the deskew control file created with the -m attribute of ppmunwarp
CONTROL_PPI="check_ppi" # The name of the ppi control file created with the -m attribute of ppmunwarp
CALIBRATION_FILE="calibration.bin" # The full file name of the binary calibration data
UNWARP_OPT="-mul 5.08" # Options to ppmunwarp. Change according to your setup. Note: the mul attribute is a multiplier to the pixel-count. Since there are 5.08 calibration points pr. inch (i.e. 2*2.54), we must multiply the pixel count between two adjacent calibration dots with 5.08 to get the PPI
CORRECTED_POSTFIX="_corrected" # the postfix of corrected images. E.g. the file "PAGE01_R.PPM" becomes "PAGE_01_POSTFIX.PPM"
COLOR_CORRECTION_METHOD="imagemagick" #options for imagemagick and ufraw - leave blank if no color correction is desired
DPI_CALCULATION_METHOD="automatic" #options are automatic, manual, and autocheck
IM_VERBOSE_OPTION="" #use "-verbose" if imagemagick details are desired, otherwise leave blank
IM_FINAL_OUTPUT_OPTION="-format tif -compress lzw" #set desired output format and compression options -- for tif with lzw compression, use "-format tif -compress lzw"

#Imagemagick Color Correction Options
#True RGB values of Gray Card
TRUE_RED=162
TRUE_GREEN=162
TRUE_BLUE=160
COLOR_CROP_AREA="500x500" #crop area for the gray card in the center in order to find the average color of the gray card. If the crop area extends beyond the gray card, color correction will be incorrect.

# Include current folder in search path for program ppmunwarp
PATH=$PATH:`pwd`

###Color Correction###

##Using Imagemagick to Fix Colors

if [ "$COLOR_CORRECTION_METHOD" == "imagemagick" ];
	then
	#Convert RAW file extension and crop an area in the center of calibration image
	convert $COLOR_IMAGE.$INPUT_FORMAT -gravity center -crop "$COLOR_CROP_AREA"+0+0 color-test.png

	#Determine average colors in cropped area
	SOURCE_RED=$(convert color-test.png -resize 1x1 -format "%[fx:int(255*p{10,10}.r)]" info:)
	SOURCE_GREEN=$(convert color-test.png -resize 1x1 -format "%[fx:int(255*p{10,10}.g)]" info:)
	SOURCE_BLUE=$(convert color-test.png -resize 1x1 -format "%[fx:int(255*p{10,10}.b)]" info:)

	#Calculate necessary adjustments
	RED_ADJUST="$(echo "scale=10; $TRUE_RED/$SOURCE_RED" | bc)"
	GREEN_ADJUST="$(echo "scale=10; $TRUE_GREEN/$SOURCE_GREEN" | bc)"
	BLUE_ADJUST="$(echo "scale=10; $TRUE_BLUE/$SOURCE_BLUE" | bc)"

	#Adjust Colors and Output Raw images as ppm files
	echo -e "Running Imagemagick to adjust colors and convert $INPUT_FORMAT to $OUTPUT_FORMAT..."
	mogrify -format ppm $IM_VERBOSE_OPTION  -color-matrix "$RED_ADJUST 0 0 0 $GREEN_ADJUST 0 0 0 $BLUE_ADJUST" *.$INPUT_FORMAT
	
	#Remove temporary file
	rm color-test.png
	echo -e "done"
	
##Using UFRaw to Fix Colors

elif [ "$COLOR_CORRECTION_METHOD" == "ufraw" ];

	#1. select an area on your gray card,
	#2. click the eyedropper, which equalizes RGB values
	#3. adjust the exposure control to get RGB values to their ultimate goal.
	#4. Input values in the script

	then
	#Interactive variables
	echo "The color calibration image is being loaded in UFRaw. Enter the following values for color correction"
	ufraw $COLORIMAGE.$INPUT_FORMAT &
	echo "Color temperature?: "
	read UFRAW_TEMP
	echo "Green Value?: "
	read UFRAW_GREEN
	echo "Exposure change?: "
	read UFRAW_EXPOSURE
	
	##Convert all files of INPUT_FORMAT to OUTPUT_FORMAT
	echo -e "\nRunning ufraw-batch, this will take a while..."
	ufraw-batch --out-type=$OUTPUT_FORMAT *.$INPUT_FORMAT #--temperature=$UFRAW_TEMP --green=$UFRAW_GREEN --exposure=$UFRAW_EXPOSURE 
	echo -e "done"

##No Color Correction

else
	echo "No color correction will be done"
	echo "Preparing images for ppmunwarp..."
	mogrify -format ppm -verbose *.$INPUT_FORMAT
	echo -e "done"	
fi

###Geometry Correction###

##Calibration

echo -e "\nCalculating calibration data from image: $CALIBRATION_IMAGE.$OUTPUT_FORMAT"
ppmunwarp $UNWARP_OPT -m "$CONTROL_IMAGE.$OUTPUT_FORMAT" "$CALIBRATION_IMAGE.$OUTPUT_FORMAT" > "$CALIBRATION_FILE"
echo -e "done"

##Correction

echo -e "\nCorrecting geometry.  This will take some time..."
for i in *.ppm; do
 if [ -e "$i" ]; then
   FILE=`basename "$i" .ppm`
   ppmunwarp $UNWARP_OPT -d calibration.bin "$i" > "$FILE$CORRECTED_POSTFIX.$OUTPUT_FORMAT"
 fi
done
echo -e "done"

###DPI Calculation###

if [ "$DPI_CALCULATION_METHOD" == "automatic" ];
	then
	##Calculating PPI in software
	echo -e "\nCalculating calibration data from image: $CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT"
	PPI=$(( (ppmunwarp $UNWARP_OPT -m "$CONTROL_PPI.$OUTPUT_FORMAT" "$CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT") 1>/dev/null ) 2>&1)
	echo "$PPI"
	PPI=`echo "$PPI" | grep -o "Average: [0-9\.]*, calculated from [0-9]* of [0-9]* data points. PPI: [0-9]*" | sed -r 's/.*PPI: ([0-9]*).*/\1/g'`
	echo "Calculated PPI is: $PPI"

elif [ "$DPI_CALCULATION_METHOD" == "manual" ];
	then
	##Open Image in GIMP
	gimp "$CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT" &
	
	##Enter PPI
	echo "PixelsPerInch?: "
	read PPI
	echo "PPI is set to: $PPI"

elif [ "$DPI_CALCULATION_METHOD" == "autocheck" ];
	##Autodetecting DPI and comparing with a manual measurment in GIMP
	then
	
	##Calculating PPI in software
	echo -e "\nCalculating calibration data from image: $CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT"
	PPI=$(( (ppmunwarp $UNWARP_OPT -m "$CONTROL_PPI.$OUTPUT_FORMAT" "$CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT") 1>/dev/null ) 2>&1)
	echo "$PPI"

	##Checking with GIMP
	gimp "$CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT" &
	
	
	##Compare automatic and manual
	PPI=`echo "$PPI" | grep -o "Average: [0-9\.]*, calculated from [0-9]* of [0-9]* data points. PPI: [0-9]*" | sed -r 's/.*PPI: ([0-9]*).*/\1/g'`
	echo "Calculated PPI is: $PPI"
	echo "Is this correct? If not, insert corrected value now. If correct, leave empty and press enter"
	read PPI_CORRECTED
	if [ "$PPI_CORRECTED" != "" ]
	then
		PPI=$PPI_CORRECTED
	fi
	echo "PPI is set to: $PPI"
	

else
	#If config option is left blank or is incorrect, no DPI will be entered
	echo " "
	echo "No DPI calculation has been done."
	echo "ImageMagick will now prepare images for Scantailor..."
	mogrify $IM_VERBOSE_OPTION $IM_FINAL_OUTPUT_OPTION *[$CORRECTED_POSTFIX].ppm
	rm *.ppm
	echo "done"
	exit
fi

	
###Preparing Images for Scantailor###
echo ""
echo "ImageMagick will now prepare images for Scantailor..."
mogrify $IM_VERBOSE_OPTION $IM_FINAL_OUTPUT_OPTION -density $PPI -units PixelsPerInch *[$CORRECTED_POSTFIX].ppm
echo "done"


###Housekeeping###

#Delete temporary files
rm *.ppm

Some new options have been added:
DPI_CALCULATION_METHOD -- set to "automatic" to use what is autodetected, "manual" if you want to measure in GIMP, and "autocheck" to double-check the automatic detection in GIMP. If left blank or mistyped, the script won't insert DPI information, but will still complete the final steps.
IM_VERBOSE_OPTION -- I've decided that having imagemagick running in verbose mode is a bit annoying. If you want the verbose output use "-verbose," otherwise leave blank
IM_FINAL_OUTPUT_OPTION -- set the necessary "-format" and other options desired for the final output files. e.g. "-format tif -compress lzw"

Other Changes:
I've changed the COLOR_CROP_SIZE option to COLOR_CROP_AREA to allow for rectangular areas of a gray card rather than a square. e.g. Format is "500x500" for a 500 pixel square. "1000x500" for a rectangle, etc...
Some generic code cleanup
Also added "done" echoes when steps are completed.

One potential issue:
If someone had a white card and any of the RGB values from the photo were 0, there would be a divide by zero error. I don't really care enough to deal with it, since I only use gray cards. (It wouldn't be too difficult, I suppose). Gray should do a better job anyway.

Is there anything left to do before we consider this complete? If we are done, I'll make a new thread in the software section and declare a release. This one is getting a bit long for folks to know which one to use.

I'm thinking about writing a second script to call the first in cases of left and right directories, allowing a single command to do all the pre-processing work for a book. (renaming files, moving files, rotating, etc...)
abmartin
Posts: 79
Joined: 15 Sep 2010, 15:33
Number of books owned: 2000
Country: USA
Location: Ohio

Re: Preprocessing RAW images for Scantailor

Post by abmartin »

I found a couple more issues that have been fixed. I left one of the imagemagick verbose options turned on rather than using the variable. Also, I have fixed a few issues with the text output to make things more consistent. I have also added a bit more on-screen info in the color-correction stage.

I also added a log file. I did it the ugly way by cloning the bash output rather than a more elegant solution. While I probably still should add exits on errors, I think that the log file should provide the necessary information of where things went wrong. (The steps after an error will fail anyway, since the necessary files won't be there...)

I've tested it as well as I can with different config options and it seems to be working well now. I'm thrilled to be able to do it all automatically now! I wrote a short script last night to run this process on 9 books and had it run unattended. Perfect.

Let me know if things work or not.

Code: Select all

#!/bin/bash

(

###Scantailor Preprocessor###
#Fixes color with a gray card and geometry with ppmunwarp and a calibration grid
#Dependencies: Imagemagick, ppmunwarp as modified by royeven, Ufraw (only needed for RAW), Ufraw-batch (only needed for RAW), GIMP (if manual DPI calculation is desired)
#Written by abmartin and royeven at www.diybookscanner.org

###Configuration###

# Global "variables"
INPUT_FORMAT="JPG" #Change as appropriate
OUTPUT_FORMAT="ppm" #Do not change
COLOR_IMAGE="color" # The file name (without extension) of the gray card photo
CALIBRATION_IMAGE="calibration" # The file name (without extension) of the geometry calibration file
CONTROL_IMAGE="check" # The name of the deskew control file created with the -m attribute of ppmunwarp
CONTROL_PPI="check_ppi" # The name of the ppi control file created with the -m attribute of ppmunwarp
CALIBRATION_FILE="calibration.bin" # The full file name of the binary calibration data
UNWARP_OPT="-mul 5.08" # Options to ppmunwarp. Change according to your setup. Note: the mul attribute is a multiplier to the pixel-count. Since there are 5.08 calibration points pr. inch (i.e. 2*2.54), we must multiply the pixel count between two adjacent calibration dots with 5.08 to get the PPI
CORRECTED_POSTFIX="_corrected" # the postfix of corrected images. E.g. the file "PAGE01_R.PPM" becomes "PAGE_01_POSTFIX.PPM"
COLOR_CORRECTION_METHOD="imagemagick" #options for imagemagick and ufraw - leave blank if no color correction is desired
DPI_CALCULATION_METHOD="automatic" #options are automatic, manual, and autocheck
IM_VERBOSE_OPTION="" #use "-verbose" if imagemagick details are desired, otherwise leave blank
IM_FINAL_OUTPUT_OPTION="-format tif -compress lzw" #set desired output format and compression options -- for tif with lzw compression, use "-format tif -compress lzw"

#Imagemagick Color Correction Options
#True RGB values of Gray Card
TRUE_RED=162
TRUE_GREEN=162
TRUE_BLUE=160
COLOR_CROP_AREA="500x500" #crop area for the gray card in the center in order to find the average color of the gray card. If the crop area extends beyond the gray card, color correction will be incorrect.

# Include current folder in search path for program ppmunwarp
PATH=$PATH:`pwd`

echo -e "\nYour camera images are now being prepared for Scantailor"

###Color Correction###

##Using Imagemagick to Fix Colors

if [ "$COLOR_CORRECTION_METHOD" == "imagemagick" ];
	then
	
	echo -e "\nDetermining RGB values of $COLOR_IMAGE.$INPUT_FORMAT..."
	#Convert RAW file extension and crop an area in the center of calibration image
	convert $COLOR_IMAGE.$INPUT_FORMAT -gravity center -crop "$COLOR_CROP_AREA"+0+0 color-test.png

	#Determine average colors in cropped area
	SOURCE_RED=$(convert color-test.png -resize 1x1 -format "%[fx:int(255*p{10,10}.r)]" info:)
	SOURCE_GREEN=$(convert color-test.png -resize 1x1 -format "%[fx:int(255*p{10,10}.g)]" info:)
	SOURCE_BLUE=$(convert color-test.png -resize 1x1 -format "%[fx:int(255*p{10,10}.b)]" info:)
	echo "Detected RGB values are $SOURCE_RED, $SOURCE_GREEN, $SOURCE_BLUE"
	
	#Calculate necessary adjustments
	RED_ADJUST="$(echo "scale=10; $TRUE_RED/$SOURCE_RED" | bc)"
	GREEN_ADJUST="$(echo "scale=10; $TRUE_GREEN/$SOURCE_GREEN" | bc)"
	BLUE_ADJUST="$(echo "scale=10; $TRUE_BLUE/$SOURCE_BLUE" | bc)"
	echo "RGB values to be adjusted by $RED_ADJUST, $GREEN_ADJUST, $BLUE_ADJUST"

	#Adjust Colors and Output Raw images as ppm files
	echo -e "\nRunning Imagemagick to adjust colors and convert $INPUT_FORMAT to $OUTPUT_FORMAT..."
	mogrify -format ppm $IM_VERBOSE_OPTION  -color-matrix "$RED_ADJUST 0 0 0 $GREEN_ADJUST 0 0 0 $BLUE_ADJUST" *.$INPUT_FORMAT
	
	#Remove temporary file
	rm color-test.png
	echo "done"
	
##Using UFRaw to Fix Colors

elif [ "$COLOR_CORRECTION_METHOD" == "ufraw" ];

	#1. select an area on your gray card,
	#2. click the eyedropper, which equalizes RGB values
	#3. adjust the exposure control to get RGB values to their ultimate goal.
	#4. Input values in the script

	then
	#Interactive variables
	echo -e "\nThe color calibration image is being loaded in UFRaw. Enter the following values for color correction"
	ufraw $COLORIMAGE.$INPUT_FORMAT &
	echo "Color temperature?: "
	read UFRAW_TEMP
	echo "Green Value?: "
	read UFRAW_GREEN
	echo "Exposure change?: "
	read UFRAW_EXPOSURE
	
	##Convert all files of INPUT_FORMAT to OUTPUT_FORMAT
	echo -e "\nRunning ufraw-batch, this will take a while..."
	ufraw-batch --out-type=$OUTPUT_FORMAT *.$INPUT_FORMAT #--temperature=$UFRAW_TEMP --green=$UFRAW_GREEN --exposure=$UFRAW_EXPOSURE 
	echo "done"

##No Color Correction

else
	echo -e "\nNo color correction will be done"
	echo "Preparing images for ppmunwarp by converting $INPUT_FORMAT to $OUTPUT_FORMAT"
	mogrify -format ppm $IM_VERBOSE_OPTION *.$INPUT_FORMAT
	echo "done"	
fi

###Geometry Correction###

##Calibration

echo -e "\nCalculating geometry calibration data from image: $CALIBRATION_IMAGE.$OUTPUT_FORMAT"
ppmunwarp $UNWARP_OPT -m "$CONTROL_IMAGE.$OUTPUT_FORMAT" "$CALIBRATION_IMAGE.$OUTPUT_FORMAT" > "$CALIBRATION_FILE"
echo -e "done"

##Correction

echo -e "\nCorrecting geometry.  This will take some time..."
for i in *.ppm; do
 if [ -e "$i" ]; then
   FILE=`basename "$i" .ppm`
   ppmunwarp $UNWARP_OPT -d calibration.bin "$i" > "$FILE$CORRECTED_POSTFIX.$OUTPUT_FORMAT"
 fi
done
echo -e "done"

###DPI Calculation###

if [ "$DPI_CALCULATION_METHOD" == "automatic" ];
	then
	##Calculating PPI in software
	echo -e "\nCalculating DPI from image: $CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT"
	PPI=$(( (ppmunwarp $UNWARP_OPT -m "$CONTROL_PPI.$OUTPUT_FORMAT" "$CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT") 1>/dev/null ) 2>&1)
	echo "$PPI"
	PPI=`echo "$PPI" | grep -o "Average: [0-9\.]*, calculated from [0-9]* of [0-9]* data points. PPI: [0-9]*" | sed -r 's/.*PPI: ([0-9]*).*/\1/g'`
	echo "Calculated PPI is: $PPI"

elif [ "$DPI_CALCULATION_METHOD" == "manual" ];
	then
	##Open Image in GIMP
	echo -e "\n$CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT is being opened in GIMP"
	echo "Manually determine the PixelsPerInch" 
	gimp "$CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT" &
	
	##Enter PPI
	echo -e "\nPixelsPerInch?: "
	read PPI
	echo "PPI is set to: $PPI"

elif [ "$DPI_CALCULATION_METHOD" == "autocheck" ];
	##Autodetecting DPI and comparing with a manual measurment in GIMP
	then
	
	##Calculating PPI in software
	echo -e "\nCalculating calibration data from image: $CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT"
	PPI=$(( (ppmunwarp $UNWARP_OPT -m "$CONTROL_PPI.$OUTPUT_FORMAT" "$CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT") 1>/dev/null ) 2>&1)
	echo "$PPI"

	##Checking with GIMP
	gimp "$CALIBRATION_IMAGE$CORRECTED_POSTFIX.$OUTPUT_FORMAT" &
	
	
	##Compare automatic and manual
	PPI=`echo "$PPI" | grep -o "Average: [0-9\.]*, calculated from [0-9]* of [0-9]* data points. PPI: [0-9]*" | sed -r 's/.*PPI: ([0-9]*).*/\1/g'`
	echo "Calculated PPI is: $PPI"
	echo "Is this correct? If not, insert corrected value now. If correct, leave empty and press enter"
	read PPI_CORRECTED
	if [ "$PPI_CORRECTED" != "" ]
	then
		PPI=$PPI_CORRECTED
	fi
	echo "PPI is set to: $PPI"
	

else
	#If config option is left blank or is incorrect, no DPI will be entered
	echo -e "\nDPI information has neither been calculated nor manually entered."
	echo "ImageMagick will now prepare images for Scantailor..."
	mogrify $IM_VERBOSE_OPTION $IM_FINAL_OUTPUT_OPTION *[$CORRECTED_POSTFIX].ppm
	rm *.ppm
	echo "done"
	exit
fi

	
###Preparing Images for Scantailor###
echo -e "\nImageMagick will now prepare images for Scantailor..."
mogrify $IM_VERBOSE_OPTION $IM_FINAL_OUTPUT_OPTION -density $PPI -units PixelsPerInch *[$CORRECTED_POSTFIX].ppm
echo "done"


###Housekeeping###

#Delete temporary files
echo -e "\nDeleting temporary files..."
rm *.ppm
echo "done"

echo -e "\nYour images are ready for Scantailor"
exit
) 2>&1 | tee preprocess.log

pablitoclavito
Posts: 39
Joined: 12 Sep 2012, 16:54
E-book readers owned: Iliad
Number of books owned: 200
Country: Spain

Re: Preprocessing RAW images for Scantailor

Post by pablitoclavito »

It worked perfectly!

I encourage the rest of you to try it, it simplifies things a lot before going to Scantailor.
One thing I want to make clear is that the errors I was getting before in my previous posts, they were just a problem with the skin in lubuntu, nothing to do with the script or ppmunwarp, so you can use this with no problems. In fact, even with those "harmless" errors (just related to the way things are displayed), the final files are OK.

Thank you.
adamzero
Posts: 6
Joined: 03 Jul 2013, 02:30
E-book readers owned: ipad
Number of books owned: 1000
Country: USA

Re: Preprocessing RAW images for Scantailor

Post by adamzero »

Hi everyone, I'm having trouble.

I'm running this on OS X, on jpgs, in automatic dpi mode, without color calibration. "calibration.bin" is zero bytes, and (thus?) so is every other "*_corrected.ppm" file. What's going wrong and how do I fix it?

EDIT: Apologies for posting this in the RAW-oriented thread. I've reposted it in a more appropriate place.

Here's the log:

Code: Select all

Your camera images are now being prepared for Scantailor

No color correction will be done
Preparing images for ppmunwarp by converting jpg to ppm
done

Calculating geometry calibration data from image: calibration.ppm
Number of detected points: 4483
Only 2087 detected points used for calibration!
Average: 78.385221, calculated from 1622 of 2043 data points. PPI: 398
!!! Error in ppmunwarp:
!!! Distance too large for extrapolation!
done

Correcting geometry.  This will take some time...
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
!!! Error in ppmunwarp:
!!! Couldn't read deformation map file 'calibration.bin'!
done

Calculating DPI from image: calibration_corrected.ppm
!!! Error in ppmunwarp:
!!! PPM image file 'calibration_corrected.ppm' has wrong preamble!
Calculated PPI is: 

ImageMagick will now prepare images for Scantailor...
mogrify: invalid argument for option `-units': -density @ error/mogrify.c/MogrifyImageCommand/4340.
done

Deleting temporary files...
done

Your images are ready for Scantailor
Post Reply