My good friend Robert,
Put the software aside for a moment. The problem you are trying to resolve occurs well before the application software becomes involved. You need to understand the digitization of the image first. Was the image from a scanner or a camera? Let's say it came from your scanner.
What occurred between the face of the stamp and what pops up on your monitor? First, your scanner collected what IT thinks are the proper colors. There are many, many factors which can cause your scanner to read the color. He biggest is light; color is a function of light waves. The scanner tries to be consistent with the light source (the bubs/LEDS) but no two are perfectly alike. The bulbs might be a bit older and loss some intensity; this will subtlety change how your scanner 'sees' the color shade. The user may or may not have the scanner lid closed; your scanner will try to account for this the ambient light and this will change the color shade. So even if everyone in the world used the same scanner model, these things may still be not result in the same image shades. And of course the truth is that there are many, many scanners in the world that folks use.
But let's assume that that each scanner is exactly the same model, the bulbs are exactly the same, the users all scan exactly the same. Now what? Well, each scanner has a driver; this is the piece of software that tells the scanner how to interface and work with the specific computer it is hooked to. So while you and I have the same scanner, you are using a Linux driver while I am using a Windows driver. Even if they have the same algorithm in the drive code, there are enough difference to yield different results. But wait, there are different versions of the same driver! So even if we both use the same scanner and Linux but you have newer version of the driver then I do, the result could end up being different.
And finally we get to putting the image on your PC. If the image was saved it absolutely needs to be done in a format that does not compresses the image at all. In other words, if your scanner saved the image to your computer as a jpg, it has already applied compression which interprets many of the pixels and has manipulated them. You can never, put faith into a save , compressed format and think that it is an accurate depiction of the real life stamp shading.
And of course we have not even yet started to talk about the application software you are using, which applies even ore interpretation.
What scanners and computers do is give very good looking results for photos and images and typical usage. This is perfectly fine for the vast majority of folks who use scanned images to communicate. Scanning your family vacation photos, pets, or to sell something on
ebay are fine uses. But you are trying to get into a very scientific area where the computer does things like thresholds. It doesn't matter what you app does at this level, it is already full of so many variables that it is hopeless to think it can be used as a standard.
Don