I’m proud to share my first release of a tool that I’ve been working on for a bit now. Born from my own necessity, this tool aims to speed up the workflow for sharing images of collectible cards.
One of the steps for sharing basic, but high quality images of your card/slab is to ensure it is straight and the whitespace around isn’t too big. Whether you’re using a camera or a scanner, the direct output from these devices requires some processing effort.
With this new tool you no longer have to bother with scanner-bed-guides or photoshop, simply load the images into the tool and watch the magic happen (well there’s a bit more to it, but more on that later).
The python script I wrote uses canny edge detection between parts of the image that are bright (i.e. the card) and dark (i.e. the background). I could go into the nitty gritty, but I won’t bore you with it. The only thing you should keep in mind is that the background should be darker than the card or slab.
Below I’ve supplied a link to my Github repository, there can find a download link for the programm as well as the code. Once started you will be presented with the user interface:
required; click to select the input file.
optional but recommended; click to see a binary preview of the image .
optional; click to select an output folder, if no output folder is specified, the result will be saved to the input folder.
required; this is the threshold for the binary image , the slider allows you to find the sweet spot.  is required if you wish to see the effect on the preview. Ideally the card is entirely white, and the background entirely black. For me the range 30-50 has given the best results.
4. example threshold slider
optional but recommended; this value determines the amount of pixels around your card which will be preserved. When left blank, a value of 0 is assumed (no buffer around the card).
required; Run the script. Note there is no indication that the script is finished. Start at  afterwards if you wish to process more images.
You can obtain an installer (setup.exe, no python required), or the source code here, under Assets. The executable should immediately function on any windows pc, the source code contains a few scripts. Aside from the direct source code for the executable (Straighten_And_Crop.py), it also contains the two scripts which together allow you to run this code for multiple images at once (Straight_Crop_Cardpics.py and houghlines.py).
By no means is this code flawless, it requires good input to produce the best results, so generally speaking: rubbish in, rubbish out. Aside from this general principle a few things I’ve encountered in testing:
- Raw cards with dark borders give the hardest time. This includes: V-cards, English backs, Japanese old backs.
- The script is set up to detect a single card, having multiple cards in the frame will probably not work.
- Trying actively to break the script will definitely work, smuggling characters where they’re not supposed to be can crash the script. It is currently not idiot-proof.
Q: The script is giving me an error, what am I doing wrong?
A: If you’re trying to run the python script, but it doesn’t work, make sure you have installed all the required packages and have the scripts in the same directory. If that wasn’t the issue please contact me.
Q: How will I know where to find the output file?
A: The output file is saved to the directory you specified, if you didn’t specify an output directory, it will be in the same as where the input file is located. Output files are written as “X_[original filename]”.
Q: I’m getting a sliver of an image as output, why is that?
A: The binary image is probably not good enough, and the script is only detecting 2 or 3 “strong” edges. Try playing around with the threshold value. Alternatively, if the output image would be larger than the original image, this can also happen. If that is the case, try decreasing the buffer-value.
Q: I have found a bug with the script, what do I do?
A: Please contact me so I can try to patch it.
Q: Will you work on improving the current version?
A: There are a lot of improvements possible (e.g. processing multiple images simultaneously with the .exe), but the current version works well enough for me. Before I commit a lot of time I wish to know people actually are using this. So it depends…
Thanks for reading, and good luck with your images! This is a beta release of sorts, so expect things to go awry from time to time (I am a mere hobbyist in this space). If you have suggestions or wish to support me, don’t hesitate to get in touch.
I want to give a special shoutout to @pfm, who’s been producing a near identical product parallel to me (and had been doing so well before I started). If my software isn’t to your liking, maybe you could try theirs!