Algorithm to calculate 'treat as white' value on a scanned image
I've got an image that I'm scanning in from the scanner. There's an area of the image that deliberately doesn't contain anything (so just white). The rest of the image contains data that needs analysing. This plain white area (called the 'reference area') should be used to determine what value the analysis code should treat as "white". Coming from a scanner, white isn't always going to be 255.
Then the rest of the image (the analysis area) is then extrapolated to be in-between 0 and this white point.
I've tried getting the average (mean) of all pixels in the r开发者_运维百科eference area, but the value isn't always what I want.
Any ideas on the best algorithm to use to calculate this "treat as white" value?
The best way to do it will depend on various things, such as what form of noise, artefacts or other sources of error occur in your data, what later processing you need to do. Having said that, given that you have a known reference area, a fairly simple approach should work.
Rather than finding the mean, find the k-th lowest value in the reference area, where k is, say, 15% of the number of pixels in the reference area. The idea of this is to find the dimmest white in the reference area, so that everything brighter than that will be saturated to white when you adjust the image values. You probably don't want to pick the absolute lowest pixel value from the reference area, because then you're very likely to pick a pixel that was not actually white (a speck of dust/smudge/sensor noise or some other artefact).
More generally, you may want to look into automatic thresholding algorithms, which will give you other (somewhat more sophisticated) ways of selecting the white-point.
I'm assuming greyscale image processing for all of this. Full colour constancy (part of which comes from determining the white point of an image) is a much harder problem, though having a white reference area in your image would certainly help with this too.
精彩评论