Algorithmix.Preprocessing.Preprocessing.TransparencyFilter C# (CSharp) Method

TransparencyFilter() public static method

Simple helper function that will test to make sure that more than a certain percentage of the shred is non a transparent color.
public static TransparencyFilter ( Bitmap shred ) : bool
shred System.Drawing.Bitmap
return bool
        public static bool TransparencyFilter(Bitmap shred)
        {
            Image<Bgr, Byte> image1 = new Image<Bgr, byte>(shred);

            Image<Bgr, byte> transparentImage = image1.And(new Bgr(Color.Transparent));
            long nonTransparent = transparentImage.CountNonzero().Sum();
            long totalPixels = transparentImage.Height * transparentImage.Width;
            double ratio = (double)nonTransparent / (double)totalPixels;
            return (ratio > MinTransparencyRatio);
        }