Best way to detect blank transparent image
Posted: 2018-03-05T12:52:39-07:00
I want to determine the best/fastest way to detect if an image is entirely blank (assume image has alpha channel).
Test image https://www.dropbox.com/s/46zdazxrgy83g ... y.png?dl=0
Possible approaches:
1. Check for mean of zero (or standard deviation of zero?)
identify -format "%[opaque] %[fx:mean] %[fx:standard_deviation]" empty.png
False 0 0
Note: Photoshop reports mean of 255, so perhaps standard deviation is best value to go by?
Also, for my sample image, Imagemagick reports it as a Greyscale with Alpha, Photoshop treats it as RGB with Alpha - not sure why)
2. Check bounding box
identify -format "[%k]" emtpy.png
identify: geometry does not contain image `empty.png' @ warning/attribute.c/GetImageBoundingBox/240.
[0x0+855+540]
I like this approach since Imagemagick gives a nice warning message - any caveats to this technique?
Version: ImageMagick 7.0.7-14 Q16 x64 2017-12-06
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype gslib jng jp2 jpeg lcms lqr openexr pangocairo png ps raw rsvg tiff webp xml zlib
Test image https://www.dropbox.com/s/46zdazxrgy83g ... y.png?dl=0
Possible approaches:
1. Check for mean of zero (or standard deviation of zero?)
identify -format "%[opaque] %[fx:mean] %[fx:standard_deviation]" empty.png
False 0 0
Note: Photoshop reports mean of 255, so perhaps standard deviation is best value to go by?
Also, for my sample image, Imagemagick reports it as a Greyscale with Alpha, Photoshop treats it as RGB with Alpha - not sure why)
2. Check bounding box
identify -format "[%k]" emtpy.png
identify: geometry does not contain image `empty.png' @ warning/attribute.c/GetImageBoundingBox/240.
[0x0+855+540]
I like this approach since Imagemagick gives a nice warning message - any caveats to this technique?
Version: ImageMagick 7.0.7-14 Q16 x64 2017-12-06
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype gslib jng jp2 jpeg lcms lqr openexr pangocairo png ps raw rsvg tiff webp xml zlib