Пример #1
0
        public Bitmap GetNewFrame(Bitmap source)
        {
            var newFrame = levelsLinear.Apply(source);

            source.Dispose();
            return(newFrame);
        }
Пример #2
0
 private static Bitmap CreateGrayscale(Bitmap image)
 {
     
     const int size = 512;
     float scale = Math.Min(size / (float)image.Width, size / (float)image.Height);
     ResizeBicubic resize = new ResizeBicubic((int)(image.Width*scale), (int)(image.Height*scale));
     
     ImageStatistics stat = new ImageStatistics( image );
     LevelsLinear levelsLinear = new LevelsLinear
     {
         Output = new IntRange(0, 255),
         InRed = stat.Red.GetRange(.95),
         InBlue = stat.Blue.GetRange(.95),
         InGreen = stat.Green.GetRange(.95)
     };
     SaturationCorrection sc = new SaturationCorrection(-1);
     Bitmap square = new Bitmap(size, size);
     using(Bitmap resized = resize.Apply(sc.Apply(levelsLinear.Apply(image)).MakeGrayscale()))
     using (Graphics g = Graphics.FromImage(square))
     {
         g.DrawImage(resized, new Point((size-resized.Width) / 2 ,0));
     }
     
     return square;
 }
Пример #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Bitmap img = null;

            DA.GetData(0, ref img);
            Interval L = new Interval(0, 1);

            DA.GetData("Luminance", ref L);
            Interval S = new Interval(0, 1);

            DA.GetData("Saturation", ref S);
            Interval Y = new Interval(0, 255);

            DA.GetData("Luma", ref Y);
            Interval Cb = new Interval(-1, 1);

            DA.GetData("Chroma_Blue", ref Cb);
            Interval Cr = new Interval(-1, 1);

            DA.GetData("Chroma_Red", ref Cr);
            Interval R = new Interval(0, 255);

            DA.GetData("Red", ref R);
            Interval G = new Interval(0, 255);

            DA.GetData("Green", ref G);
            Interval B = new Interval(0, 255);

            DA.GetData("Blue", ref B);

            Bitmap filteredImage = img;

            Interval bInterval        = new Interval(0, 1);
            Interval Interval255      = new Interval(0, 255);
            Interval IntervalMinusOne = new Interval(-1, 1);

            //////////////////////////////////////////////////////////////////////////
            HSLLinear myHSLfilter = new HSLLinear();

            if (bInterval.IncludesInterval(L))
            {
                myHSLfilter.InLuminance = new AForge.Range(Convert.ToSingle(L.Min), Convert.ToSingle(L.Max));
            }
            if (bInterval.IncludesInterval(S))
            {
                myHSLfilter.InSaturation = new AForge.Range(Convert.ToSingle(S.Min), Convert.ToSingle(S.Max));
            }
            filteredImage = myHSLfilter.Apply(img);
            //////////////////////////////////////////////////////////////////////////
            YCbCrLinear myYCbCrfilter = new YCbCrLinear();

            if (Interval255.IncludesInterval(Y))
            {
                myYCbCrfilter.InCb = new AForge.Range(Convert.ToSingle(Y.Min), Convert.ToSingle(Y.Max));
            }
            if (IntervalMinusOne.IncludesInterval(Cb))
            {
                myYCbCrfilter.InCb = new AForge.Range(Convert.ToSingle(Cb.Min), Convert.ToSingle(Cb.Max));
            }
            if (IntervalMinusOne.IncludesInterval(Cr))
            {
                myYCbCrfilter.InCr = new AForge.Range(Convert.ToSingle(Cr.Min), Convert.ToSingle(Cr.Max));
            }
            filteredImage = myYCbCrfilter.Apply(filteredImage);
            //////////////////////////////////////////////////////////////////////////
            LevelsLinear myRGBfilter = new LevelsLinear();

            if (Interval255.IncludesInterval(R))
            {
                myRGBfilter.InRed = new AForge.IntRange((int)(R.Min), (int)(R.Max));
            }
            if (Interval255.IncludesInterval(G))
            {
                myRGBfilter.InGreen = new AForge.IntRange((int)(G.Min), (int)(G.Max));
            }
            if (Interval255.IncludesInterval(B))
            {
                myRGBfilter.InBlue = new AForge.IntRange((int)(B.Min), (int)(B.Max));
            }
            filteredImage = myRGBfilter.Apply(filteredImage);

            DA.SetData(0, filteredImage);
        }