Пример #1
0
 private void myTestFun()
 {
     Mapper map = new Mapper(0.9, new Point(10, 10), new Point(5, 5),
         4, 16, 10, 11, 12, 13, 14, 15, 16, 17, false);
     MappedPoint mp = map.MapPoint(11, 10, 20);
     Bitmap bitmap = (Bitmap)Bitmap.FromFile(@"C:\Documents and Settings\Marcin\Pulpit\lena.jpg");
     int sdelta = 4;
     int bdelta = 16;
     Domain d = new Domain(new Point(0,0),new Point(0,bdelta),
         new Point(bdelta,bdelta),new Point(bdelta,0), bdelta / sdelta);
     Structure.Region r = new Structure.Region(new Point(0,0),new Point(0,sdelta),
         new Point(sdelta,sdelta),new Point(sdelta,0));
     double s = MNTools.ComputeContractivityFactor(d, r, bitmap);
 }
Пример #2
0
        public Bitmap DecompressImageVerII(out Bitmap bitmapWithGrid)
        {
            Bitmap bit = new Bitmap(width, height,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Queue<MappedPoint>[] domainsPoints = PrepareLists();
            Graphics.FromImage(bit).FillRectangle(Brushes.Green, 0, 0, this.width, this.height);

            //punkty interpolacyjne
            foreach (MappedPoint p in interpolationPoints)
            {
                bit.SetPixel(p.X, p.Y,
                        Color.FromArgb((int)p.Val,
                        (int)p.Val,
                        (int)p.Val));
                interPixel++;
            }

            //g³owna petla
            bool newPixel = true;
            int cos=0;
            Random rand = new Random();
            while (newPixel)
              //  while(cos<10)
            {
                newPixel = false;
                Console.Out.WriteLine("Iteration " + cos++);
                for (int i = 0; i < interpolationPoints.Count; i+=4)
                {
                    int address = addresses[i / 4];
                    double s = contractivityFactors[i / 4];
                   // address = rand.Next(numberOfDomainInHeight * numberOfDomainInWidth);
                   // s = rand.NextDouble();
                    if (address != -1)
                    {
                        MyDomain domain = FindDomainByAddress(address);
                        Mapper mapper = new Mapper(s, domain.Domain.Vertices[1],
                                interpolationPoints[i + 1], smallDelta, bigDelta,
                                domain.Vals[0], domain.Vals[1], domain.Vals[2], domain.Vals[3],
                                (int)interpolationPoints[i].Val, (int)interpolationPoints[i + 1].Val,
                                (int)interpolationPoints[i + 2].Val, (int)interpolationPoints[i + 3].Val, false);
                            int sizeOfQueue = domainsPoints[address].Count;
                            for (int j = 0; j < sizeOfQueue; j++)
                            {
                                MappedPoint point = domainsPoints[address].Dequeue();
                                domainsPoints[address].Enqueue(point);
                                MappedPoint newPoint = mapper.MapPoint(point.X, point.Y, point.Val);
                                if (SafePutPixel((int)newPoint.X, (int)newPoint.Y, (int)newPoint.Val, bit))
                                {
                                    newPixel = true;
                                    int domainAddress = FindDomainByPoint(newPoint);
                                    domainsPoints[domainAddress].Enqueue(newPoint);
                                }
                            }

                    }
                }
            }

            //tworzenie siatki
            bitmapWithGrid = (Bitmap)bit.Clone();
            for (int i = 0; i < interpolationPoints.Count; i += 4)
            {
                for (int k = interpolationPoints[i + 1].Y; k < interpolationPoints[i].Y; k++)
                {
                    bitmapWithGrid.SetPixel(interpolationPoints[i + 1].X, k, Color.Red);
                    bitmapWithGrid.SetPixel(interpolationPoints[i + 2].X, k, Color.Red);
                }
                for (int k = interpolationPoints[i + 1].X; k < interpolationPoints[i + 2].X; k++)
                {
                    bitmapWithGrid.SetPixel(k, interpolationPoints[i + 1].Y, Color.Red);
                    bitmapWithGrid.SetPixel(k, interpolationPoints[i].Y, Color.Red);
                }
            }
            Console.Out.WriteLine(goodPixel + " " + badPixel+" "+interPixel);
            return bit;
        }
Пример #3
0
 public Bitmap DecompressImage(out Bitmap bitmapWithGrid)
 {
     int steps = (int)Math.Truncate(Math.Log(smallDelta, 2) / Math.Log(a, 2));
     Bitmap bit = new Bitmap(width, height,
         System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     foreach (MappedPoint p in interpolationPoints)
     {
         bit.SetPixel(p.X, p.Y,
                 Color.FromArgb((int)p.Val,
                 (int)p.Val,
                 (int)p.Val));
         interPixel++;
     }
     for (int t = 0; t < steps; t++)
     {
         for (int i = 0; i < Math.Min(steps, dMax); i++)
         {
             for (int j = 0; j < this.interpolationPoints.Count; j += 4)
             {
                 int coresspondingDomain = addresses[j / 4];
                 if (coresspondingDomain != -1)
                 {
                     double contractivityFactor = contractivityFactors[j / 4];
                     //contractivityFactor = 0;
                     MyDomain md = FindDomainByAddress(coresspondingDomain);
                     Mapper mapper = new Mapper(contractivityFactor,
                         md.Domain.Vertices[1], interpolationPoints[j + 1],
                         this.smallDelta, this.bigDelta,
                          md.Vals[0], md.Vals[1], md.Vals[2], md.Vals[3],
                         (int)interpolationPoints[j].Val,
                          (int)interpolationPoints[j + 1].Val,
                         (int)interpolationPoints[j + 2].Val,
                         (int)interpolationPoints[j + 3].Val,
                          false);
                     Point[] prevPoint = md.Domain.Vertices;
                     int[] prevVal = md.Vals;
                     for (int k = 0; k < md.Domain.Size * md.Domain.Size; k++)
                     {
                         MappedPoint[] newPoint = new MappedPoint[prevPoint.Length];
                         for (int pp = 1; pp <= 1; pp++)
                         {
                             newPoint[pp] = mapper.MapPoint(prevPoint[pp].X,
                                  prevPoint[pp].Y, (double)prevVal[pp]);
                             Structure.Region tempRegion = FindRegion(newPoint[pp]);
                             if (tempAdd != -1 && tempS != -1)
                             {
                                 md = FindDomainByAddress(tempAdd);
                                 mapper = new Mapper(tempS, md.Domain.Vertices[1], tempRegion.Vertices[1],
                                      this.smallDelta, this.bigDelta,
                                      md.Vals[0], md.Vals[1], md.Vals[2], md.Vals[3],
                                     (int)tempRegion[0, tempRegion.Size],
                                     (int)tempRegion[0, 0],
                                     (int)tempRegion[tempRegion.Size, 0],
                                     (int)tempRegion[tempRegion.Size, tempRegion.Size],
                                     true);
                                 Console.Out.WriteLine(md.Domain.Vertices[1].X + " " + md.Domain.Vertices[1].Y
                                 + " " + md.Domain.Vertices[2].X + " " + md.Domain.Vertices[2].Y
                                 + " " + md.Domain.Vertices[3].X + " " + md.Domain.Vertices[3].Y
                                 + " " + md.Domain.Vertices[0].X + " " + md.Domain.Vertices[0].Y);
                             }
                             SafePutPixel(newPoint[pp].X, newPoint[pp].Y, (int)newPoint[pp].Val
                                          , bit);
                             prevPoint[pp] = newPoint[pp];
                             prevVal[pp] = (int)newPoint[pp].Val;
                         }
                     }
                 }
             }
         }
     }
     Console.Out.WriteLine(goodPixel + " " + badPixel);
     bitmapWithGrid = (Bitmap)bit.Clone();
     for (int i = 0; i < interpolationPoints.Count; i += 4)
     {
         for (int k = interpolationPoints[i + 1].Y; k < interpolationPoints[i].Y; k++)
         {
             bitmapWithGrid.SetPixel(interpolationPoints[i + 1].X, k, Color.Red);
             bitmapWithGrid.SetPixel(interpolationPoints[i + 2].X, k, Color.Red);
         }
         for (int k = interpolationPoints[i + 1].X; k < interpolationPoints[i + 2].X; k++)
         {
             bitmapWithGrid.SetPixel(k, interpolationPoints[i + 1].Y, Color.Red);
             bitmapWithGrid.SetPixel(k, interpolationPoints[i].Y, Color.Red);
         }
     }
     return bit;
 }
Пример #4
0
        public static FractalCompression.Structure.Region MapDomainToRegion(Domain domain, FractalCompression.Structure.Region region, Bitmap bitmap, Mapper mapper, int a)
        {
            //int smallDelta = region.Size + 1;
            int bigDelta = domain.Size + 1;
            int smallDelta = bigDelta / a;
            int domainMaxX = domain.Vertices[3].X;
            Point regCorner = region.Vertices[1];

            double[,] mappedVals = new double [smallDelta, smallDelta];

            int x, y;
            for (int i = 0; i < bigDelta; i++)
            {
                y = domain.Vertices[1].Y + i;
                x = domain.Vertices[1].X;
                if (i == 0)
                {
                    mappedVals[0, 0] = MNTools.GetBitmapValue(region.Vertices[1].X, region.Vertices[1].Y, bitmap);
                    for (int j = 1; j < bigDelta; ++j)
                    {
                        x += a;
                        if (x > domainMaxX)
                            break;
                        MappedPoint mp = mapper.MapPoint(x, y, MNTools.GetBitmapValue(x, y, bitmap));
                        mappedVals[mp.X - regCorner.X, mp.Y - regCorner.Y] = mp.Val;
                    }
                    mappedVals[0, smallDelta - 1] = MNTools.GetBitmapValue(region.Vertices[2].X, region.Vertices[2].Y, bitmap);
                }
                else if (i == bigDelta - 1)
                {
                    mappedVals[0, smallDelta - 1] = MNTools.GetBitmapValue(region.Vertices[0].X, region.Vertices[0].Y, bitmap);
                    for (int j = 1; j < bigDelta; ++j)
                    {
                        x += a;
                        if (x > domainMaxX)
                            break;
                        MappedPoint mp = mapper.MapPoint(x, y, MNTools.GetBitmapValue(x, y, bitmap));
                        mappedVals[mp.X - regCorner.X, mp.Y - regCorner.Y] = mp.Val;
                    }
                    mappedVals[smallDelta - 1, smallDelta - 1] = MNTools.GetBitmapValue(region.Vertices[3].X, region.Vertices[3].Y, bitmap);
                }
                else
                {
                    for (int j = 0; j < bigDelta; ++j)
                    {
                        x += a;
                        if (x > domainMaxX)
                            break;
                        MappedPoint mp = mapper.MapPoint(x, y, MNTools.GetBitmapValue(x, y, bitmap));
                        mappedVals[mp.X - regCorner.X, mp.Y - regCorner.Y] = mp.Val;
                    }
                }
            }

            FractalCompression.Structure.Region mappedRegion = new FractalCompression.Structure.Region(region.Vertices, mappedVals);
            return mappedRegion;
        }