Ejemplo n.º 1
0
 public RawImage MarkSeams(RawImage img, Color color)
 {
     switch (type)
     {
         case SeamType.Vertical:
             return MarkVerticalSeams(img, color);
         default:
             return MarkVerticalSeams(img, color);
     }
 }
Ejemplo n.º 2
0
 public RawImage RemoveSeams(RawImage img)
 {
     switch (type)
     {
         case SeamType.Vertical:
             return RemoveVerticalSeamsFromImage(img);
         default:
             return RemoveHorizontalSeamsFromImage(img);
     }
 }
Ejemplo n.º 3
0
        public void ModifyInPlace(ref RawImage rim)
        {
            rim.Lock();

            for (int x = 0; x < rim.Width; ++x)
            {
                for (int y = 0; y < rim.Height; ++y)
                {
                    rim[x, y] = Lookup(rim[x,y]);
                }
            }
        }
Ejemplo n.º 4
0
        public Bitmap RemoveHorizontalSeam(List<int> seam)
        {
            int x = img.Width - 1;
            RawImage ni = new RawImage(img.Width, img.Height - 1);

            foreach (var skip in seam)
            {
                for (int y = 0; y < skip - 1; ++y)
                    ni[x, y] = img[x, y];

                for (int y = skip + 1; y < img.Height; ++y)
                    ni[x, y - 1] = img[x, y];

                --x;
            }

            return ni.Image;
        }
Ejemplo n.º 5
0
        public WindowBrightnessContrast(WindowPicture wnd, Modification mt)
        {
            InitializeComponent();

            mod = new RawImage((Bitmap)wnd.Image);
            pic = wnd;
            original = new RawImage((Bitmap)wnd.Image);
            type = mt;
            apply = false;

            switch (mt)
            {
                case Modification.Brightness:
                    tb.Minimum = -255;
                    tb.Maximum = 255;
                    tb.Value = 0;
                    Text = label1.Text = "Brightness";
                    break;
                case Modification.Contrast:
                    tb.Maximum = 50;
                    tb.Minimum = -50;
                    tb.Value = 0;
                    Text = label1.Text = "Contrast";
                    break;
                case Modification.Gamma:
                    tb.Minimum = 10;
                    tb.Maximum = 200;
                    Text = label1.Text = "Gamma";
                    tb.Value = 100;
                    break;
                case Modification.Exposition:
                    tb.Minimum = -2000;
                    tb.Maximum = 2000;
                    tb.Value = 0;
                    Text = label1.Text = "Exposition";
                    break;
                case Modification.Threshold:
                    tb.Minimum = 0;
                    tb.Maximum = 255;
                    tb.Value = 128;
                    Text = label1.Text = "Threshold";
                    break;
            }
        }
Ejemplo n.º 6
0
        private void Edge(ref RawImage rim, RawImage org)
        {
            width = rim.Width;
            height = rim.Height;
            int val;

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    val = org[MirrorX(x - 1), y, RawImage.Channel.Red] + org[MirrorX(x + 1), y, RawImage.Channel.Red]
                        + org[MirrorX(x - 1), MirrorY(y - 1), RawImage.Channel.Red] + org[MirrorX(x + 1), MirrorY(y - 1), RawImage.Channel.Red]
                        + org[MirrorX(x - 1), MirrorY(y + 1), RawImage.Channel.Red] + org[MirrorX(x + 1), MirrorY(y + 1), RawImage.Channel.Red]
                        + org[x, MirrorY(y - 1), RawImage.Channel.Red] + org[x, MirrorY(y - 1), RawImage.Channel.Red];

                    val -= 8 * org[x, y, RawImage.Channel.Red];
                    val = Utils.Clamp<int>(val, 0, 255);
                    rim[x, y] = Color.FromArgb(val, val, val);
                }
            }
        }
Ejemplo n.º 7
0
        public WindowConvultion(WindowPicture wnd)
        {
            InitializeComponent();

            filter = new int[5, 5];
            filter[3, 3] = 1;

            pic = wnd;
            mod = new RawImage((Bitmap) wnd.Image);
            original = new RawImage((Bitmap) wnd.Image);

            for (int i = 0; i < 5; ++i)
                filterData.Columns.Add("", "");

            for (int i = 0; i < 5; ++i)
                filterData.Rows.Add(0, 0, 0, 0, 0);

            filterData[2, 2].Value = 1;

            filterData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            filterData.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            filterData.ColumnHeadersVisible = false;
        }
Ejemplo n.º 8
0
        public Bitmap AddVerticalSeams(List<List<int>> seams)
        {
            RawImage ni = new RawImage(img.Width + seams.Count, img.Height);

            for (int y = img.Height - 1; y >= 0; --y)
            {
                for (int x = 0; x < img.Width; ++x)
                    ni[x, y] = img[x, y];
            }

            int tmpWidth = img.Width;

            //foreach (var seam in seams)
            {
                //tmpWidth += 1;
                for (int y = img.Height - 1; y >= 0; --y)
                {
                    //int add = seam[y];

                    List<int> tmp = new List<int>(seams.Count);
                    foreach (var s in seams)
                        tmp.Add(s[y]);

                    tmp.Sort();
                    tmp.Reverse();

                    for (int dx = 0; dx < tmp.Count; ++dx)
                    {
                        for (int x = tmpWidth + tmp.Count; x > tmp[dx]; --x)
                            ni[x, y] = ni[x - 1, y];
                        ni[tmp[dx], y] = LinearGradient(ni[tmp[dx] + 1, y], ni[tmp[dx], y], 0.75f);
                    }
                }
            }

            return ni.Image;
        }
Ejemplo n.º 9
0
        private void sepiaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form f = ActiveMdiChild;

            if (f != null && f is WindowPicture)
            {
                WindowPicture pic = f as WindowPicture;
                RawImage raw = new RawImage((Bitmap)pic.Image);

                pic.Image = lut.Modify(raw).Image;
            }
        }
Ejemplo n.º 10
0
        private void negativeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form f = ActiveMdiChild;
            if (f != null && f is WindowPicture)
            {
                WindowPicture pic = f as WindowPicture;

                RawImage mod = new RawImage((Bitmap) pic.Image);
                Color c;

                for (int y = 0; y < mod.Height; ++y)
                {
                    for (int x = 0; x < mod.Width; ++x)
                    {
                        c = mod[x,y];
                        mod[x, y] = Color.FromArgb( 255 - c.R, 255 - c.G, 255 - c.B );
                    }
                }

                pic.Image = mod.Image;
            }
        }
Ejemplo n.º 11
0
        private void grayscaleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form f = ActiveMdiChild;
            if (f != null && f is WindowPicture)
            {
                WindowPicture pic = f as WindowPicture;

                RawImage mod = new RawImage((Bitmap)pic.Image);
                Color c;
                byte gs;

                for (int y = 0; y < mod.Height; ++y)
                {
                    for (int x = 0; x < mod.Width; ++x)
                    {
                        c = mod[x, y];
                        gs = (byte)(0.299 * c.R + 0.587 * c.G + 0.114 * c.B);
                        mod[x, y] = Color.FromArgb(gs,gs,gs);
                    }
                }

                pic.Image = mod.Image;
            }
        }
Ejemplo n.º 12
0
 public SeamCarving(Image image)
 {
     img = new RawImage((Bitmap)image);
     Allocate();
 }
Ejemplo n.º 13
0
        private RawImage RemoveVerticalSeamsFromImage(RawImage img)
        {
            RawImage rim = new RawImage(img.Width - seamsCount, img.Height);

            for (int y = 0; y < img.Height; ++y)
            {
                List<int> list = seams[y];
                int dx = 0;

                for (int x = 0; x < img.Width; ++x)
                {
                    //TODO: do quicker
                    if (list.Contains(x))
                        continue;

                    rim[dx, y] = img[x, y];
                    ++dx;
                }
            }

            return rim;
        }
Ejemplo n.º 14
0
        private RawImage RemoveHorizontalSeamsFromImage(RawImage img)
        {
            RawImage rim = new RawImage(img.Width, img.Height - seamsCount);

            for (int x = 0; x < img.Width; ++x)
            {
                List<int> list = seams[x];
                int dy = 0;

                for (int y = 0; y < img.Height; ++y)
                {
                    //TODO: do quicker
                    if (list.Contains(y))
                        continue;

                    rim[x, dy] = img[x, y];
                    ++dy;
                }
            }

            return rim;
        }
Ejemplo n.º 15
0
        private RawImage MarkVerticalSeams(RawImage img, Color color)
        {
            RawImage rim = new RawImage(img.Width, img.Height);

            for (int y = 0; y < img.Height; ++y)
            {
                List<int> list = seams[y];

                for (int x = 0; x < img.Width; ++x)
                {
                    //TODO: do quicker
                    if (list.Contains(x))
                        rim[x, y] = color;
                    else
                        rim[x, y] = img[x, y];
                }
            }

            return rim;
        }
Ejemplo n.º 16
0
        private RawImage MarkHorizontalSeams(RawImage img, Color color)
        {
            RawImage rim = new RawImage(img.Width, img.Height);

            for (int x = 0; x < img.Width; ++x)
            {
                List<int> list = seams[x];

                for (int y = 0; y < img.Height; ++y)
                {
                    if (list.Contains(y))
                        rim[x,y] = color;
                    else
                        rim[x,y] = img[x,y];
                }
            }

            return rim;
        }
Ejemplo n.º 17
0
        internal Image Retarget(int nwidth, int nheight, System.ComponentModel.BackgroundWorker bg)
        {
            int hdiff = img.Width - nwidth;
            int vdiff = img.Height - nheight;
            int steps = 0;
            int step = 0;

            steps += Math.Abs(hdiff);
            steps += Math.Abs(vdiff);

            if (hdiff > 0)
            {
                while (hdiff-- > 0)
                {
                    ComputeGradient();
                    ComputeVerticalEnergy();
                    img = new RawImage(RemoveVerticalSeam(FindVerticalSeam()));

                    ++step;

                    if (bg != null)
                        bg.ReportProgress(step * 100 / steps);
                }
            }
            else if (hdiff != 0)
            {
                int founded = Math.Abs(hdiff);
                int need = founded;

                do
                {
                    Allocate(0, founded);
                    ComputeGradient();
                    ComputeVerticalEnergy();

                    RawImage tmp = new RawImage(AddVerticalSeams(FindVerticalSeams(founded, ref founded)));

                    step += founded;
                    need -= founded;

                    if (founded > 0)
                        img = tmp;

                    if (bg != null)
                        bg.ReportProgress(step * 100 / steps);

                } while (need > 0);
            }

            if (vdiff > 0)
            {
                while (vdiff-- > 0)
                {
                    ComputeGradient();
                    ComputeHorizontalEnergy();
                    img = new RawImage(RemoveHorizontalSeam(FindHorizontalSeam()));

                    ++step;

                    if (bg != null)
                        bg.ReportProgress(step * 100 / steps);
                }
            }

            if (bg != null)
                bg.ReportProgress(100);

            return img.Image;
        }
Ejemplo n.º 18
0
 public RawImage Modify(RawImage rim)
 {
     RawImage tmp = (RawImage)rim.Clone();
     ModifyInPlace(ref rim);
     return tmp;
 }
Ejemplo n.º 19
0
 public void ModifyInPlace(ref RawImage rim)
 {
     rim = Modify(rim);
 }
Ejemplo n.º 20
0
 public RawImage Modify(RawImage rim)
 {
     RawImage tmp = new RawImage(rim.Width, rim.Height);
     Edge(ref tmp,rim);
     return tmp;
 }
Ejemplo n.º 21
0
        public Bitmap RemoveVerticalSeam(List<int> seam)
        {
            int y = img.Height - 1;
            RawImage ni = new RawImage(img.Width - 1, img.Height);

            foreach(var skip in seam)
            {
                for (int x = 0; x < skip; ++x)
                    ni[x, y] = img[x, y];

                for (int x = skip + 1; x < img.Width; ++x)
                    ni[x - 1, y] = img[x, y];
                --y;
            }

            return ni.Image;
        }