Kevin's decision can be accelerated using random sampling. If you have an idea of ββthe percentage of pixels that should be different from the background (provided that you are not dealing with a large number of images with only one pixel), you can use the Poisson distribution:
the probability of finding a non-empty pixel = 1 - e ^ (- n * p)
where n is the number of samples to try, and p is the percentage of pixels that are expected to be non-empty. Solve for n to get the appropriate number of samples to try:
n = -log (1 - x) / p
where x is the desired probability and log is the natural log. For example, if you are sure that 0.1% of the image should be non-empty, and you want to have a 99.99% chance of finding at least one non-empty pixel,
n = -log (1-.9999) /. 001 = 9210 required samples.
Much faster than checking each pixel. To be 100% sure, you can always go back and check everything if the sample does not find.
Aaron koller
source share