Skip to content

Instantly share code, notes, and snippets.

@retrography
Created September 16, 2014 06:50
Show Gist options
  • Save retrography/ba4a9b95cc3b3fb9b99a to your computer and use it in GitHub Desktop.
Save retrography/ba4a9b95cc3b3fb9b99a to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment