Having just finished a large project involving cropping and adjusting levels for 9000 images with Photoshop actions I decided it was worth looking at IM while the pain points were still fresh in our minds to see if there was a more efficient way. For now, I'm restricting things to WinXP/7 and DOS batch files for reasons that have nothing to do with which OS is better.
The images: Photographs, copied using a DSLR camera on a dark background
Photoshop action: Add dark border, magic wand select near 0,0, smooth selection to include noise (dust etc...), invert selection, expand selection to add some padding around the photograph and crop.
This worked pretty well with only a few under/over-cropped images. After some hunting around and exploring much further into DOS than I'd ever been before I managed to hack some of the examples together to do pretty much the same sort of thing. To get the numbers for the filtering in the first step I gradually added commands to produce the BW image that would be the "mask". Some of the numbers would change for our full resolution images but I don't think you could automatically assume the size of a noise particle (dust, hairs etc...) as a percentage of the image size.
Code: Select all
setlocal FOR /F "tokens=*" %%i in ('convert %1 -virtual-pixel edge -auto-level -threshold 15%% -morphology smooth octagon:4^ -morphology dilate octagon:2 -morphology dilate octagon:10 -bordercolor black -border 1x1 -trim -format "%%wx%%h%%O" info:') do SET IMTEST=%%i convert %1 -bordercolor black -border 1x1 -crop %IMTEST% +repage %~n1_trim.tif
I may look at some edge detection processing to see if it's possible to exaggerate the edge of the print without doing the same for a particle of the same width... any suggestions?