示例#1
0
        private bool ProcessIteration()
        {
            if (Best.Generation == 0)
            {
                Best = new GARepresentation(WorkingImg.GetBitmap().Width, WorkingImg.GetBitmap().Height);
                SeedRepresentation(Best);
            }

            GARepresentation nextgen = Best.Duplicate();

            nextgen.Mutate(Entropy, Properties);

            nextgen.DrawToFastBitmap(WorkingImg);
            double nextcomp = FastBitmap.UltraCompare(Img, WorkingImg);

            if ((nextcomp < BestComparison) || ((nextcomp == BestComparison) && (nextgen.Shapes.Count < Best.Shapes.Count)))
            {
                Best           = nextgen;
                BestComparison = nextcomp;
                Best.Generation++;

                return(true);
            }

            return(false);
        }
示例#2
0
        public void ComputeBackground(FastBitmap source)
        {
            ColourHistogram ch = new ColourHistogram(source.GetBitmap());

            BackgroundColour = ch.MostFrequent();
            ch.Dispose();
        }
示例#3
0
        public void Load()
        {
            FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read);

            try
            {
                BinaryReader br     = new BinaryReader(fs);
                string       header = br.ReadString();
                if (header == "GAVECTORPROJECT")
                {
                    byte major = br.ReadByte();
                    byte minor = br.ReadByte();

                    if ((major < VERSIONMAJOR) || ((major == VERSIONMAJOR) && (minor <= VERSIONMINOR)))
                    {
                        GZipStream gz = new GZipStream(fs, CompressionMode.Decompress);

                        br = new BinaryReader(gz);

                        //Load The Image to a MemoryStream
                        float resx = br.ReadSingle();
                        float resy = br.ReadSingle();

                        int          bmlength = br.ReadInt32();
                        byte[]       buffer   = br.ReadBytes(bmlength);
                        MemoryStream ms       = new MemoryStream(buffer);
                        Bitmap       bt       = new Bitmap(ms);
                        bt.SetResolution(resx, resy);
                        ms.Close();
                        buffer = null;

                        // Draw the Bitmap onto a 24bpp canvas
                        SourceImage = new FastBitmap(bt.Width, bt.Height, PixelFormat.Format24bppRgb);
                        Graphics gp = Graphics.FromImage(SourceImage.GetBitmap());
                        gp.DrawImage(bt, PointF.Empty);
                        gp.Dispose();

                        Properties     = new GAProjectProperties(br);
                        BestYet        = new GARepresentation(br);
                        BestComparison = br.ReadDouble();
                    }
                    else
                    {
                        throw new Exception("Version incorrect, this version " + VERSIONMAJOR.ToString() + "." + VERSIONMINOR.ToString() + ", file version " + major.ToString() + "." + minor.ToString());
                    }
                }
                else
                {
                    throw new Exception("Not a GAVector Project File");
                }
            }
            catch (IOException)
            {
                throw new Exception("File is Corrupt");
            }
            finally
            {
                fs.Close();
            }
        }
示例#4
0
        public unsafe void DrawToFastBitmap(FastBitmap bitmap)
        {
            Graphics gp = Graphics.FromImage(bitmap.GetBitmap());

            gp.Clear(BackgroundColour);
            Draw(new GdiGraphics(gp));
            gp.Dispose();
        }
示例#5
0
 private void DisplayImageBitmap(FastBitmap imagebitmap)
 {
     lock (imagebitmap)
     {
         displayimagebitmap = (Bitmap)imagebitmap.GetBitmap().Clone();
     }
     changed = true;
 }
示例#6
0
        private void SeedRepresentation(GARepresentation rep)
        {
            if (Properties.BackgroundColorFromHistogram)
            {
                rep.ComputeBackground(Img);
            }

            switch (Properties.Seeding)
            {
            case GASeeding.RandomSeed:
                rep.GenericSeed(Entropy, Properties);
                break;

            case GASeeding.MatrixSeed:
                rep.MatrixSeed(Img.GetBitmap(), Properties);
                break;
            }
        }
示例#7
0
        public void Save()
        {
            FileStream fs = new FileStream(Filename, FileMode.Create, FileAccess.Write);

            // Header, Version
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write("GAVECTORPROJECT");
            bw.Write((byte)VERSIONMAJOR);
            bw.Write((byte)VERSIONMINOR);
            bw.Dispose();
            //Compressed Contents
            GZipStream gz = new GZipStream(fs, CompressionMode.Compress);

            bw = new BinaryWriter(gz);

            //Bitmap & Resolution
            Bitmap b = SourceImage.GetBitmap();

            bw.Write((float)b.HorizontalResolution);
            bw.Write((float)b.VerticalResolution);
            MemoryStream ms = new MemoryStream();

            b.Save(ms, ImageFormat.Tiff);
            bw.Write((int)ms.Length);
            bw.Flush();
            ms.WriteTo(gz);
            ms.Close();
            bw.Flush();

            Properties.WriteBinary(bw);
            BestYet.WriteBinary(bw);
            bw.Write(BestComparison);
            bw.Flush();

            Changed = false;
        }