Esempio n. 1
0
        private void ApplyWhiteBalance(MagickImage image)
        {
            using (var mask = image.Clone())
            {
                mask.ColorSpace = ColorSpace.HSB;
                mask.Negate(Channels.Green);

                using (var newMask = mask.Separate(Channels.Green).First())
                {
                    using (var maskBlue = mask.Separate(Channels.Blue).First())
                    {
                        newMask.Composite(maskBlue, CompositeOperator.Multiply);
                    }

                    newMask.ContrastStretch((Percentage)0, WhiteBalance);
                    newMask.InverseOpaque(new MagickColor("white"), new MagickColor("black"));

                    double maskMean = GetMean(newMask);

                    double redRatio   = GetRatio(image, Channels.Red, newMask, maskMean);
                    double greenRatio = GetRatio(image, Channels.Green, newMask, maskMean);
                    double blueRatio  = GetRatio(image, Channels.Blue, newMask, maskMean);

                    var matrix = new MagickColorMatrix(3, redRatio, 0, 0, 0, greenRatio, 0, 0, 0, blueRatio);

                    image.ColorMatrix(matrix);
                }
            }
        }
Esempio n. 2
0
        private MagickImage GetImage()
        {
            MagickImage image = new MagickImage(RawData);

            image.ColorSpace = ColorSpace.sRGB;
            MagickColorMatrix matrix = new MagickColorMatrix(3);

            matrix.SetRow(0, 0, 0, 1);
            matrix.SetRow(1, 0, 1, 0);
            matrix.SetRow(2, 1, 0, 0);
            image.ColorMatrix(matrix);
            return(image);
        }
Esempio n. 3
0
 public override byte[] ToArray()
 {
     using (MagickImage image = new MagickImage(data))
     {
         if (image.ColorSpace != ColorSpace.sRGB)
         {
             image.ColorSpace = ColorSpace.sRGB;
         }
         MagickColorMatrix matrix = new MagickColorMatrix(3);
         matrix.SetRow(0, 0, 0, 1);
         matrix.SetRow(1, 0, 1, 0);
         matrix.SetRow(2, 1, 0, 0);
         image.ColorMatrix(matrix);
         return(image.ToByteArray());
     }
 }