Пример #1
0
        /// <summary>
        /// Calculates Shannon entropy for one image by grouppping bytes by channels
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static double ShannonEntropyByChannels(Image <Bgr, byte> image)
        {
            int size = image.Rows * image.Cols;

            byte[] data = new byte[size * image.NumberOfChannels];
            for (int m = 0; m < image.Rows; m++)
            {
                for (int n = 0; n < image.Cols; n++)
                {
                    Bgr p = image[m, n];
                    data[0 + m * image.Cols + n]        = (byte)p.Blue;
                    data[size + m * image.Cols + n]     = (byte)p.Green;
                    data[2 * size + m * image.Cols + n] = (byte)p.Red;
                }
            }

            // for each channel
            //var channels = ImageHelper.GetBgrChannelsAsByte(image);
            //double SE_B = (new DataEntropyUTF8(channels.B)).Entropy;
            //double SE_G = (new DataEntropyUTF8(channels.G)).Entropy;
            //double SE_R = (new DataEntropyUTF8(channels.R)).Entropy;
            //double SE_AVG = (SE_B + SE_G + SE_R) / 3.0;

            var SE = new DataEntropyUTF8(data);

            return(SE.Entropy);
        }
Пример #2
0
        /// <summary>
        /// Calculates Shannon entropy for image1 and image2. Retuns entropy defference of image2 and image1
        /// Positive value means enchacement (of contrast, visibility etc) in image2 comparing to image1. Negative - degradation.
        /// </summary>
        /// <param name="image1"></param>
        /// <param name="image2"></param>
        /// <returns></returns>
        //public static double ShannonEntropyDiff(Image<Gray, byte> image1, Image<Gray, byte> image2)
        //{
        //    var SE1 = new DataEntropyUTF8(image1);
        //    var SE2 = new DataEntropyUTF8(image2);
        //    double result = SE2.Entropy - SE1.Entropy;
        //    return result;
        //}

        /// <summary>
        /// Calculates Shannon entropy for image1 and image2. Retuns entropy defference of image2 and image1
        /// Positive value means enchacement (of contrast, visibility etc) in image2 comparing to image1. Negative - degradation.
        /// </summary>
        /// <param name="image1"></param>
        /// <param name="image2"></param>
        /// <returns></returns>
        public static double ShannonEntropyDiff(Image <Bgr, byte> image1, Image <Bgr, byte> image2)
        {
            // compute for while image at once (possible can cause invalid result)
            //var SE1 = new DataEntropyUTF8(image1);
            //var SE2 = new DataEntropyUTF8(image2);
            //double result = SE2.Entropy - SE1.Entropy;
            //return result;

            // compute for each channel separately
            var    channels1        = image1.Split();
            var    channels2        = image2.Split();
            double averagedEntropy1 = 0;
            double averagedEntropy2 = 0;

            for (int i = 0; i < channels1.Count(); i++)
            {
                var SE1 = new DataEntropyUTF8(channels1[i]);
                var SE2 = new DataEntropyUTF8(channels2[i]);
                averagedEntropy1 += SE1.Entropy;
                averagedEntropy2 += SE2.Entropy;
            }
            averagedEntropy1 = averagedEntropy1 / channels1.Count();
            averagedEntropy2 = averagedEntropy2 / channels2.Count();
            double result = averagedEntropy2 - averagedEntropy1;

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Calculates Shannon entropy for one image
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static double ShannonEntropy(Image <Bgr, byte> image)
        {
            var SE = new DataEntropyUTF8(image);

            return(SE.Entropy);
        }