Exemplo n.º 1
0
        private void RenderPreviews()
        {
            //render the segment previews for the visualization
            Directory.CreateDirectory(Path.Combine(outdir, "\\previews\\"));

            //read in the patterns and save out their layers
            List <PatternItem> patterns = PatternIO.GetPatterns(imagedir);

            int hpadding = 30;

            foreach (PatternItem p in patterns)
            {
                Bitmap image    = new Bitmap(p.FullPath);
                String basename = p.Name;

                if (!palettes.ContainsKey(basename))
                {
                    continue;
                }

                PaletteData palette = palettes[basename];

                ColorTemplate template = new ColorTemplate(image, palette);
                SegmentMesh   mesh     = new SegmentMesh(template);

                //create a pattern directory (Not using PatternIO here, since each pattern has its own directory anyways)
                String patternDir = Path.Combine(outdir, "previews", Util.ConvertFileName(basename, "", ""));
                Directory.CreateDirectory(patternDir);

                //for each segment, pair of adjacent segments, and group, output a preview image
                List <Segment>      segs   = mesh.getSegments();
                List <SegmentGroup> groups = mesh.getGroups();

                Bitmap original = (renderFinal)? image : template.DebugQuantization();

                Bitmap previewBase = new Bitmap(original.Width * 2 + hpadding, original.Height);
                //draw the original image on the right
                Graphics g = Graphics.FromImage(previewBase);
                g.DrawImage(original, original.Width + hpadding, 0);

                //draw a grayscaled image on the left
                for (int i = 0; i < original.Width; i++)
                {
                    for (int j = 0; j < original.Height; j++)
                    {
                        int gray = (int)Math.Round(255 * original.GetPixel(i, j).GetBrightness());
                        previewBase.SetPixel(i, j, Color.FromArgb(gray, gray, gray));
                    }
                }

                //color in orange and blue

                for (int i = 0; i < segs.Count(); i++)
                {
                    Bitmap unary = new Bitmap(previewBase);
                    foreach (var point in segs[i].points)
                    {
                        unary.SetPixel(point.X, point.Y, Color.Orange);
                    }
                    unary.Save(Path.Combine(patternDir, "s" + i + ".png"));

                    foreach (int j in segs[i].adjacencies)
                    {
                        if (j > i)
                        {
                            Bitmap binary = new Bitmap(unary);

                            Segment neighbor = segs[j];
                            foreach (var point in neighbor.points)
                            {
                                binary.SetPixel(point.X, point.Y, Color.ForestGreen);
                            }

                            binary.Save(Path.Combine(patternDir, "s" + i + "-s" + j + ".png"));
                            binary.Dispose();
                        }
                    }
                    unary.Dispose();
                }

                for (int i = 0; i < groups.Count(); i++)
                {
                    Bitmap group = new Bitmap(previewBase);
                    foreach (int j in groups[i].members)
                    {
                        Segment member = segs[j];

                        //color in the points
                        foreach (var point in member.points)
                        {
                            group.SetPixel(point.X, point.Y, Color.Orange);
                        }
                    }
                    group.Save(Path.Combine(patternDir, "g" + i + ".png"));
                    group.Dispose();
                }


                original.Dispose();
                previewBase.Dispose();
            }
        }
        private void RenderPreviews()
        {
            //render the segment previews for the visualization
            Directory.CreateDirectory(Path.Combine(outdir, "\\previews\\"));

            //read in the patterns and save out their layers
            List<PatternItem> patterns = PatternIO.GetPatterns(imagedir);

            int hpadding = 30;

            foreach (PatternItem p in patterns)
            {

                Bitmap image = new Bitmap(p.FullPath);
                String basename = p.Name;

                if (!palettes.ContainsKey(basename))
                    continue;

                PaletteData palette = palettes[basename];

                ColorTemplate template = new ColorTemplate(image, palette);
                SegmentMesh mesh = new SegmentMesh(template);

                //create a pattern directory (Not using PatternIO here, since each pattern has its own directory anyways)
                String patternDir = Path.Combine(outdir, "previews", Util.ConvertFileName(basename, "",""));
                Directory.CreateDirectory(patternDir);

                //for each segment, pair of adjacent segments, and group, output a preview image
                List<Segment> segs = mesh.getSegments();
                List<SegmentGroup> groups = mesh.getGroups();

                Bitmap original = (renderFinal)? image : template.DebugQuantization();

                Bitmap previewBase = new Bitmap(original.Width*2+hpadding, original.Height);
                //draw the original image on the right
                Graphics g = Graphics.FromImage(previewBase);
                g.DrawImage(original, original.Width+hpadding, 0);

                //draw a grayscaled image on the left
                for (int i = 0; i < original.Width; i++)
                {
                    for (int j = 0; j < original.Height; j++)
                    {
                        int gray = (int)Math.Round(255*original.GetPixel(i, j).GetBrightness());
                        previewBase.SetPixel(i,j, Color.FromArgb(gray, gray, gray));
                    }
                }

                //color in orange and blue

                for (int i = 0; i < segs.Count(); i++)
                {
                    Bitmap unary = new Bitmap(previewBase);
                    foreach (var point in segs[i].points)
                        unary.SetPixel(point.X, point.Y, Color.Orange);
                    unary.Save(Path.Combine(patternDir, "s" + i + ".png"));

                    foreach (int j in segs[i].adjacencies)
                    {
                        if (j > i)
                        {
                            Bitmap binary = new Bitmap(unary);

                            Segment neighbor = segs[j];
                            foreach (var point in neighbor.points)
                                binary.SetPixel(point.X, point.Y, Color.ForestGreen);

                            binary.Save(Path.Combine(patternDir, "s" + i + "-s" + j + ".png"));
                            binary.Dispose();

                        }
                    }
                    unary.Dispose();
                }

                for (int i = 0; i < groups.Count(); i++)
                {
                    Bitmap group = new Bitmap(previewBase);
                    foreach (int j in groups[i].members)
                    {
                        Segment member = segs[j];

                        //color in the points
                        foreach (var point in member.points)
                            group.SetPixel(point.X, point.Y, Color.Orange);
                    }
                    group.Save(Path.Combine(patternDir, "g" + i + ".png"));
                    group.Dispose();
                }

                original.Dispose();
                previewBase.Dispose();

            }
        }