public Compressor(int bigDelta, int a, int eps, int dmax, Domain[,] domains, FractalCompression.Structure.Region[,] regions, List<MappedPoint> interpolationPoints, Bitmap bitmap) { this.bigDelta = bigDelta; this.a = a; this.smallDelta = bigDelta / a; this.eps = eps; this.dmax = dmax; this.regions = regions; this.domains = domains; squeue = new Queue<FractalCompression.Structure.Region>(); foreach (FractalCompression.Structure.Region r in regions) squeue.Enqueue(r); iqueue = new Queue<MappedPoint>(); foreach (MappedPoint mp in interpolationPoints) if (!iqueue.Contains(mp)) iqueue.Enqueue(mp); aqueue = new Queue<int>(); cqueue = new Queue<double>(); squeue2 = new Queue<FractalCompression.Structure.Region>(); d = 1; this.bitmap = bitmap; this.h = new double[regions.Length, domains.Length]; this.minHQueue = new List<double>(); }
public static bool CheckConditionOfContinuity(Domain[,] domains, int i, int j, int a, FractalCompression.Structure.Region region, Bitmap bitmap) { const double contEps = 0.5; if (i < 0 || j < 0 || (i > domains.GetUpperBound(0)) || (j > domains.GetUpperBound(1))) throw new ArgumentException("Incorrect i or j values"); Domain dij = domains[i, j]; Domain dip1j = domains[i + 1, j]; Domain dijp1 = domains[i, j + 1]; double sij = MNTools.ComputeContractivityFactor(dij, region, bitmap); double sip1j = MNTools.ComputeContractivityFactor(dip1j, region, bitmap); double sijp1 = MNTools.ComputeContractivityFactor(dijp1, region, bitmap); //TODO: spr czy na pewno v=0 (a nie 1) i v< a-1 a nie (v<a) for (int v = 1; v < a; v++) { //Console.WriteLine(sij * dij.Right(v, bitmap) + " ? " + (sip1j * dip1j.Left(v, bitmap))); /*if ((sij * dij.Right(v, bitmap)) != (sip1j * dip1j.Left(v, bitmap))) return false; if ((sij * dij.Up(v, bitmap)) != (sijp1 * dijp1.Down(v, bitmap))) return false;*/ //Console.WriteLine(Math.Abs(((sij * dij.Right(v, bitmap)) - (sip1j * dip1j.Left(v, bitmap))))); //Console.WriteLine(Math.Abs(((sij * dij.Up(v, bitmap)) - (sijp1 * dijp1.Down(v, bitmap))))); if (Math.Abs(((sij * dij.Right(v, bitmap)) - (sip1j * dip1j.Left(v, bitmap)))) > contEps) return false; if (Math.Abs(((sij * dij.Up(v, bitmap)) - (sijp1 * dijp1.Down(v, bitmap)))) > contEps) return false; } //Console.WriteLine("condition of continuity true"); return true; }
public static double ComputeContractivityFactor(Domain domain, FractalCompression.Structure.Region region, Bitmap bitmap) { double u = 0, v = 0; /* double cosu = 0, cosv = 0; int ile = 0; if (domain.WasUCounted) cosu = domain.U; else { for (int i = domain.Vertices[1].X; i < domain.Vertices[2].X; i++) for (int j = domain.Vertices[1].Y; j < domain.Vertices[0].Y; j++) { cosu += bitmap.GetPixel(i, j).B; ile++; } cosu = cosu / ile; domain.U = cosu; domain.WasUCounted = true; } if (region.WasVCounted) cosv = region.V; else { ile = 0; for (int i = region.Vertices[1].X; i < region.Vertices[2].X; i++) for (int j = region.Vertices[1].Y; j < region.Vertices[0].Y; j++) { cosv += bitmap.GetPixel(i, j).B; ile++; } cosv = cosv / ile; region.V = cosv; region.WasVCounted = true; } return cosv / cosu;*/ //poziomo dla domeny if (domain.WasUCounted) u = domain.U; else { u += ComputeVertically2(domain.Vertices[1].X, domain.Vertices[1].Y, domain.Vertices[3].X, domain.Vertices[3].Y, bitmap); //pionowa dla domeny u += ComputeHorizontally2(domain.Vertices[1].X, domain.Vertices[1].Y, domain.Vertices[3].X, domain.Vertices[3].Y, bitmap); u = u / (2 * domain.Size); domain.U = u; domain.WasUCounted = true; } if (region.WasVCounted) v = region.V; else { //poziomo dla regionu v += ComputeVertically(region.Vertices[1].X, region.Vertices[1].Y, region.Vertices[3].X, region.Vertices[3].Y, bitmap); //pionowa dla domeny v += ComputeHorizontally(region.Vertices[1].X, region.Vertices[1].Y, region.Vertices[3].X, region.Vertices[3].Y, bitmap); v = v / (2 * region.Size); region.V = v; region.WasVCounted = true; } double alfa = Math.Log(u / v, Math.E); //return 1 / Math.Pow(2, alfa); return v / (3* u); }
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); }
public MyDomain(Domain domain, int[] vals) { this.domain = domain; this.vals = vals; }
private MyDomain FindDomainByAddress(int address) { int domainX = (address % numberOfDomainInWidth) * this.bigDelta; int domainY = (address / numberOfDomainInHeight) * this.bigDelta; MyDomain md = null; for (int i = 0; i < this.interpolationPoints.Count; i += 4) { if (domainX == interpolationPoints[i + 1].X && domainY == interpolationPoints[i + 1].Y) { int[] vals = new int[4]; Domain d = new Domain(new Point(interpolationPoints[i + 1].X, interpolationPoints[i + 1].Y + bigDelta - 1), interpolationPoints[i + 1], new Point(interpolationPoints[i + 1].X + bigDelta - 1, interpolationPoints[i + 1].Y), new Point(interpolationPoints[i + 1].X + bigDelta - 1, interpolationPoints[i + 1].Y + bigDelta - 1), this.a); vals[0] = (int)interpolationPoints[i + 4 * a * numberOfDomainInWidth - 1].Val; vals[1] = (int)interpolationPoints[i + 1].Val; vals[2] = (int)interpolationPoints[i + 6].Val; vals[3] = (int)interpolationPoints[i + 4 * a * numberOfDomainInWidth + 6].Val; md = new MyDomain(d, vals); break; } } return md; }
// a - regionsInDomainRow private static Domain[,] PrepareDomains(int bigDelta, int a, int bmpWidth, int bmpHeight, FractalCompression.Structure.Region[,] regions) { int domainsInRow = bmpWidth / bigDelta; int domainsInColumn = bmpHeight / bigDelta; Domain[,] domains = new Domain[domainsInColumn, domainsInRow]; Point[] vertices = new Point[4]; int eastX, northY = 0; for (int i = 0; i < domainsInColumn; ++i) { eastX = 0; for (int j = 0; j < domainsInRow; ++j) { vertices[0] = new Point(eastX, northY + bigDelta - 1); vertices[1] = new Point(eastX, northY); vertices[2] = new Point(eastX + bigDelta - 1, northY); vertices[3] = new Point(eastX + bigDelta - 1, northY + bigDelta - 1); domains[i, j] = new FractalCompression.Structure.Domain(vertices, a); eastX += bigDelta; } northY += bigDelta; } return domains; }
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; }