Exemplo n.º 1
0
        private void ExtractTemplate_Click(object sender, EventArgs e)
        {
            //extract templates from images in a directory
            String[] files  = Directory.GetFiles(dir, "*.png");
            String   infile = dir + "\\palettes.tsv";
            Dictionary <String, List <PaletteData> > palettes = LoadFilePalettes(infile);

            Directory.CreateDirectory(dir + "\\templates\\");
            Directory.CreateDirectory(dir + "\\recolor\\");

            Random random = new Random();

            foreach (String f in files)
            {
                Bitmap       image    = new Bitmap(Image.FromFile(f));
                Segmentation seg      = new Segmentation();
                String       basename = f.Replace(dir + "\\", "");
                String       segFile  = dir + "/segments/" + basename;
                seg.LoadFromFile(f, segFile);

                ColorTemplate template = new ColorTemplate(image, seg, palettes[basename].First());
                Bitmap        render   = template.Render();
                render.Save(dir + "\\templates\\" + basename);

                //testing random color assignments
                int numSeg = template.NumSlots();

                int[] segToColor = new int[numSeg];
                for (int t = 0; t < 3; t++)
                {
                    for (int i = 0; i < numSeg; i++)
                    {
                        segToColor[i] = random.Next(palettes[basename].First().colors.Count());
                    }

                    Bitmap recolor = template.ColorWith(palettes[basename].First(), segToColor);
                    recolor.Save(dir + "\\recolor\\" + Util.ConvertFileName(basename, "_" + t));

                    Bitmap solidcolor = template.SolidColor(palettes[basename].First(), segToColor);
                    solidcolor.Save(dir + "\\recolor\\" + Util.ConvertFileName(basename, "_" + t + "_solid"));
                }
            }
        }