/* * Analisando os seguintes pixeis * A B C * D E F * G H I * * O pixel E vai ser expandido para 9 novos pixeis * * E0 E1 E2 * E3 E4 E5 * E6 E7 E8 * */ public static Bitmap Scale3x(Bitmap b) { Bitmap dst = new Bitmap(b.Width * 3, b.Height * 3); FastBitmap fdst = new FastBitmap(dst); FastBitmap fb = new FastBitmap(b); Color A, B, C, D, E, F, G, H, I = new Color(); Color E0, E1, E2, E3, E4, E5, E6, E7, E8 = new Color(); int nDstCol1 = 0, nDstCol2 = 0, nDstCol3 = 0; int nDstLin1 = 0, nDstLin2 = 0, nDstLin3 = 0; int col1, col2, col3, lin1, lin2, lin3; for (int h = 0; h < b.Height; ++h) { nDstLin1 = nDstLin3 == 0 ? 0 : nDstLin3 + 1; nDstLin2 = nDstLin1 + 1; nDstLin3 = nDstLin2 + 1; nDstCol1 = 0; nDstCol2 = 0; nDstCol3 = 0; for (int w = 0; w < b.Width; ++w) { col1 = w - 1 < 1 ? 0 : w - 1; col2 = w; col3 = w + 1 >= b.Width ? b.Width - 1 : w + 1; lin1 = h - 1 < 1 ? 0 : h - 1; lin2 = h; lin3 = h + 1 >= b.Height ? b.Height - 1 : h + 1; A = fb.GetPixel(col1, lin1); B = fb.GetPixel(col2, lin1); C = fb.GetPixel(col3, lin1); D = fb.GetPixel(col1, lin2); E = fb.GetPixel(col2, lin2); F = fb.GetPixel(col3, lin2); G = fb.GetPixel(col1, lin3); H = fb.GetPixel(col2, lin3); I = fb.GetPixel(col3, lin3); if (B != H && D != F) { E0 = D == B ? D : E; E1 = (D == B && E != C) || (B == F && E != A) ? B : E; E2 = B == F ? F : E; E3 = (D == B && E != G) || (D == H && E != A) ? D : E; E4 = E; E5 = (B == F && E != I) || (H == F && E != C) ? F : E; E6 = D == H ? D : E; E7 = (D == H && E != I) || (H == F && E != G) ? H : E; E8 = H == F ? F : E; } else { E0 = E; E1 = E; E2 = E; E3 = E; E4 = E; E5 = E; E6 = E; E7 = E; E8 = E; } nDstCol1 = nDstCol3 == 0 ? 0 : nDstCol3 + 1; nDstCol2 = nDstCol1 + 1; nDstCol3 = nDstCol2 + 1; fdst.SetPixel(nDstCol1, nDstLin1, E0); fdst.SetPixel(nDstCol2, nDstLin1, E1); fdst.SetPixel(nDstCol3, nDstLin1, E2); fdst.SetPixel(nDstCol1, nDstLin2, E3); fdst.SetPixel(nDstCol2, nDstLin2, E4); fdst.SetPixel(nDstCol3, nDstLin2, E5); fdst.SetPixel(nDstCol1, nDstLin3, E6); fdst.SetPixel(nDstCol2, nDstLin3, E7); fdst.SetPixel(nDstCol3, nDstLin3, E8); } } b = fdst.GetBitmap(); dst.Dispose(); return(b); }
/* * Analisando os seguintes pixeis * A B C * D E F * G H I * * O pixel E vai ser expandido para 4 novos * * E0 E1 * E2 E3 * */ public static Bitmap Scale2x(Bitmap b) { Bitmap dst = new Bitmap(b.Width * 2, b.Height * 2); FastBitmap fdst = new FastBitmap(dst); FastBitmap fb = new FastBitmap(b); Color A, B, C, D, E, F, G, H, I = new Color(); Color E0, E1, E2, E3 = new Color(); int nDstCol1, nDstCol2 = 0; int nDstLin1, nDstLin2 = 0; int col1, col2, col3, lin1, lin2, lin3 = 0; for (int h = 0; h < b.Height; ++h) { nDstLin1 = nDstLin2 == 0 ? 0 : nDstLin2 + 1; nDstLin2 = nDstLin1 + 1; nDstCol1 = 0; nDstCol2 = 0; for (int w = 0; w < b.Width; ++w) { col1 = w - 1 < 1 ? 0 : w - 1; col2 = w; col3 = w + 1 >= b.Width ? b.Width - 1 : w + 1; lin1 = h - 1 < 1 ? 0 : h - 1; lin2 = h; lin3 = h + 1 >= b.Height ? b.Height - 1 : h + 1; A = fb.GetPixel(col1, lin1); B = fb.GetPixel(col2, lin1); C = fb.GetPixel(col3, lin1); D = fb.GetPixel(col1, lin2); E = fb.GetPixel(col2, lin2); F = fb.GetPixel(col3, lin2); G = fb.GetPixel(col1, lin3); H = fb.GetPixel(col2, lin3); I = fb.GetPixel(col3, lin3); E0 = D == B && B != F && D != H ? D : E; E1 = B == F && B != D && F != H ? F : E; E2 = D == H && D != B && H != F ? D : E; E3 = H == F && D != H && B != F ? F : E; /* * if (B != H && D != F) * { * E0 = D == B ? D : E; * E1 = B == F ? F : E; * E2 = D == H ? D : E; * E3 = H == F ? F : E; * } * else * { * E0 = E; * E1 = E; * E2 = E; * E3 = E; * }*/ nDstCol1 = nDstCol2 == 0 ? 0 : nDstCol2 + 1; nDstCol2 = nDstCol1 + 1; fdst.SetPixel(nDstCol1, nDstLin1, E0); fdst.SetPixel(nDstCol2, nDstLin1, E1); fdst.SetPixel(nDstCol1, nDstLin2, E2); fdst.SetPixel(nDstCol2, nDstLin2, E3); } } b = fdst.GetBitmap(); dst.Dispose(); return(b); }
/* * p11 p12 p13 * p21 p p23 * p31 p32 p33 */ internal String ImageToGraph(Bitmap b) { FastBitmap fb = new FastBitmap(b); Height = b.Height; Width = b.Width; //Le imagem orignal e adiciona vertex - nodos for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Pixel p = new Pixel(x, y, fb.GetPixel(x, y)); g.AddVertex(p); } } //Le imagem orignal e adiciona edges - arestas for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Pixel p = VertexSearch(x, y, g); Pixel p11 = VertexSearch(x - 1, y - 1, g); if (p11 != null && Pixel.colorIsSimilar(p11.color, p.color)) { var e1 = new TaggedUndirectedEdge <Pixel, EdgeTag>(p, p11, new EdgeTag()); g.AddEdge(e1); p.valence++; p11.valence++; } Pixel p12 = VertexSearch(x, y - 1, g); if (p12 != null && Pixel.colorIsSimilar(p12.color, p.color)) { var e2 = new TaggedUndirectedEdge <Pixel, EdgeTag>(p, p12, new EdgeTag()); g.AddEdge(e2); p.valence++; p12.valence++; } Pixel p13 = VertexSearch(x + 1, y - 1, g); if (p13 != null && Pixel.colorIsSimilar(p13.color, p.color)) { var e3 = new TaggedUndirectedEdge <Pixel, EdgeTag>(p, p13, new EdgeTag()); g.AddEdge(e3); p.valence++; p13.valence++; } Pixel p21 = VertexSearch(x - 1, y, g); if (p21 != null && Pixel.colorIsSimilar(p21.color, p.color)) { var e4 = new TaggedUndirectedEdge <Pixel, EdgeTag>(p, p21, new EdgeTag()); g.AddEdge(e4); p.valence++; p21.valence++; } } } SvgVector svg = new SvgVector(); svg.Height = Height; svg.Width = Width; return(svg.toImageSVG(g, "Graph.svg")); }