How can I batch-crop hundreds of coin photos while keeping a small border?
Asked 1/8/2016
5 views
2 answers
0
I regularly photograph large batches of coins and currently crop each image by hand to remove excess background while leaving a small, even border around the coin. Is there a reliable way to automate this process for many images at once? I'm interested in either a Photoshop-style workflow or a more technical approach that can detect the coin and crop around it automatically.
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
10y ago
2 Answers
4
This will probably require a bit of scripting or programming. Read up on the Circle Hough Transform. Basically, it detects circles in an image. While the maths are quite complicated, you can probably find a decent library in a language that abstracts away a lot of the complexity.
For instance, checkout the OpenCV (Open Computer Vision) library, which has C, C++, Python, and Java interfaces. As an example usage, here is a tutorial for detecting circles using OpenCV in Python. In that example, the circles vector is a list of 3-tuples, each tuple containing the (x-coordinate, y-coordinate, radius) of the found circle. To find the circle with the largest radius, something like:
largest_circle = max(circles, key=lambda c: c[2])
will find the largest circle in the image (which is presumably your coin), as the same (x, y, r) tuple. After that, you can just increase r by a small amount (to create a border), such that you can crop the image at: (xmin = x − r, xmax = x + r), by (ymin = y − r, ymax = y + r).
Rather than using OpenCV, this example uses the scikit-image image processing library with Python. The image in this example is an image of several coins lined up, showing the found circles in the image.
Originally by user11924. Source · Licensed CC BY-SA 4.0
user11924
10y ago
0
Generated from our catalog & community — verify before relying on it.
Yes—this can be automated, but the best method depends on how consistent your photos are.
If your coin shots are framed and lit very similarly, the simplest option is to use a Photoshop Action (or equivalent). Record the steps you normally perform, then batch-run that action on the whole folder. This works best when each image is nearly identical in scale and position.
If the coin size or placement varies, a computer-vision approach is more reliable. Since coins are circular, circle detection is a good fit. A common method is the Circle Hough Transform, available in libraries such as OpenCV. It can detect the coin’s center and radius; from there you can crop around the detected circle and add a fixed extra margin to keep a small border.
So in practice:
- use batch actions for consistent images
- use OpenCV/circle detection if framing varies
If your current method is based on selecting and removing a uniform background color, that can also be incorporated into a Photoshop action, but it will still depend on consistent background and lighting.
Recommended products
UniqueBot
AI10y ago
Your Answer
Related Questions
How can I split multiple photos from one flatbed scan into separate image files?
How can I batch-convert a large photo archive into screen-sized JPEGs while keeping the folder structure?
How can I batch export from Photoshop and keep the correct embedded color profile?
What software can batch compress and watermark images for web use?
What software can batch-edit EXIF data on scanned slide images?