retrography
9/16/2014 - 6:50 AM

An extension to 'negfix8' to automate negative scanning even further. Including dust removal (64-bit RGBI images), color inversion, auto-cro

An extension to 'negfix8' to automate negative scanning even further. Including dust removal (64-bit RGBI images), color inversion, auto-crop, unsharp masking, etc...

#!/bin/sh

#convert raw-rgbi-i.tif -negate -lat 10x10+2% -negate alpha.png
echo "Extracting RGB channels to rgb_$1..."

tiffcrop -N 1 $1 rgb_$1 2>/dev/null

echo "Extracting RGB channels to i_$1..."

tiffcrop -N 3 $1 i_$1 2>/dev/null

echo "Generating dust removal mask..."

convert i_$1 -threshold 80% mask_$1
convert mask_$1 -morphology thicken '1x3>:1,0,1' mask_$1
convert mask_$1 -morphology Erode Octagon mask_$1
convert mask_$1 -blur 1 mask_$1
convert -size 10x100 gradient: -rotate 90 grad_$1
convert grad_$1 -fx "2*(u-.5)" grad_$1
convert mask_$1 grad_$1 -clut mask_$1

rm grad_$1 i_$1

echo "Inverting the negative..."

negfix8 -cs rgb_$1 inv_$1 1>/dev/null

rm rgb_$1

echo "Applying dust removal..."

convert inv_$1 \( mask_$1 \) \
          -alpha off -compose CopyOpacity -composite \
          \( +clone -channel RGBA -blur 0x3 +channel -alpha off \) \
          +swap -compose over -composite \
          dedust_$1

rm inv_$1 mask_$1

echo "Cropping film borders..."

convert dedust_$1 -fuzz 50% -trim -shave 10x10 +repage -normalize -unsharp 1.5x1.2+1.0+0.10  final_$1

rm dedust_$1