normalize() 공개 정적인 메소드

public static normalize ( float val, float dmin, float dmax, float smin, float smax ) : float
val float
dmin float
dmax float
smin float
smax float
리턴 float
예제 #1
0
        /// <summary>
        /// #### Saturate [-100, 100]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW saturate(BitmapW image, float p)
        {
            p = Util.normalize(p, 0, 2, -100, 100);
            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;
                    float avg = (cr + cg + cb) / 3;

                    cr = avg + p * (cr - avg);
                    cg = avg + p * (cg - avg);
                    cb = avg + p * (cb - avg);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
예제 #2
0
        /// <summary>
        /// #### Constrast [-100, 100]
        /// </summary>
        /// <param name="f"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public BitmapW contrast(BitmapW image, float p)
        {
            p = Util.normalize(p, 0, 2, -100, 100);

            float cr = 0, cg = 0, cb = 0, ca;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B; ca = temp.A;

                    cr = 255 * contrastc(cr / 255, p);
                    cg = 255 * contrastc(cg / 255, p);
                    cb = 255 * contrastc(cb / 255, p);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(ca, 0, 255), (int)Util.clamp(cr, 0, 255),
                                                        (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }
예제 #3
0
        /// <summary>
        /// #### Expose [-100, 100]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW expose(BitmapW image, float p)
        {
            p = Util.normalize(p, -1, 1, -100, 100);
            Point c1 = new Point(0, (int)(255 * p));
            Point c2 = new Point((int)(255 - (255 * p)), 255);

            return(curves(image, new Point(0, 0), c1, c2, new Point(255, 255)));
        }
예제 #4
0
        /// <summary>
        /// #### Brighten [-100, 100]
        /// </summary>
        /// <param name="image"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public BitmapW brighten(BitmapW image, float p)
        {
            p = Util.normalize(p, -255, 255, -100, 100);
            float cr = 0, cg = 0, cb = 0;
            int   i = 0, j = 0,
                  h = image.Height(),
                  w = image.Width();

            for (i = 0; i < w; i++)
            {
                for (j = 0; j < h; j++)
                {
                    Color temp = image.GetPixel(i, j);
                    cr = temp.R; cg = temp.G; cb = temp.B;

                    cr += (p);
                    cg += (p);
                    cb += (p);

                    image.SetPixel(i, j, Color.FromArgb((int)Util.clamp(cr, 0, 255), (int)Util.clamp(cg, 0, 255), (int)Util.clamp(cb, 0, 255)));
                }
            }
            return(image);
        }