I'm trying to do some batch processing of a couple thousand images that were scanned in with a business card scanner. Due to sloppiness in the scanning process, the images are all roughly the same dimensions (varying by a couple of pixels in width and height), but there are some that are "difficult".
My ultimate goal in processing these is:
- Every image should have exactly the same physical dimensions.
- The physical cards that were scanned have rounded corners, I'd like transparency in the scanned images here.
- Every image should fill the entire dimensions with little to no blank space around the edges.
Examples of difficult images:
- The card was already a light / off-white color to begin with, so distinguishing between the areas of the image that should be transparent and not is not always easy.
- The scanner thought the card was longer than it actually was (probably due to the auto-feed process), and so some images are a hundred or two hundred pixels taller, with a white band inserted at the bottom.
Originally I had it pretty close to working. I would magic wand the bottom left and top right pixels, then trim transparent pixels to cut out dead space, then scale all images to the exact same pixel dimensions.
I think I need to solve the white horizontal band at the bottom problem using something other than magic wanding, while still having it work with images that don't have a white band (since there are thousands of these).
One idea I had is something like a magic wand where you click the pixel you want to wand around, but where you specify the pixel color instead of having it take the color from the current location. But i'm not sure if something like this exists.
A second idea is that I can manually pull out all the images that have white bands by inspection, but then I need an automated process by which to crop out all of the white bands without affecting images that already have edges similar to white to begin with.
The third option which I'm dreading is to manually fix up all of the images with white bands.