private void valueChangeUnsharp_MaskingEvent() { //Model = new List<int[]> { new int[3] { 1, 1, 1 }, new int[3] { 1, 1, 1 }, new int[3] { 1, 1, 1 } }; bitmapResult = BitmapOrigin.Clone() as Bitmap; int sum = 0; foreach (var item in Model) { foreach (var it in item) { sum += it; } } int count = Model.Count; int start = count / 2; for (int i = start; i < x - start; i++) { for (int j = start; j < y - start; j++) { int sumR = 0, sumG = 0, sumB = 0; for (int w = 0; w < count; w++) { for (int h = 0; h < count; h++) { sumR += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 0) * Model[w][h]; sumG += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 1) * Model[w][h]; sumB += Gray(bitmapResult.GetPixel(i + w - start, j + h - start), 2) * Model[w][h]; } } bitmapResult.SetPixel(i, j, Color.FromArgb(sumR / sum, sumG / sum, sumB / sum)); } } // 2 * BitmapOrigin - bitmapResult for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { int[] colorO = new int[3] { BitmapOrigin.GetPixel(i, j).R, BitmapOrigin.GetPixel(i, j).G, BitmapOrigin.GetPixel(i, j).B }; int[] colorR = new int[3] { bitmapResult.GetPixel(i, j).R, bitmapResult.GetPixel(i, j).G, bitmapResult.GetPixel(i, j).B }; int[] color = new int[3]; for (int c = 0; c < 3; c++) { color[c] = Range(2 * colorO[c] - colorR[c]); } bitmapResult.SetPixel(i, j, Color.FromArgb(color[0], color[1], color[2])); } } }
private void Math_Add() { x = BitmapO2.Width; y = BitmapO2.Height; int[,,] color = new int[3, x, y]; int start = 1; //叠加原图 for (int i = start; i < x - start; i++) { for (int j = start; j < y - start; j++) { Color pixR = BitmapO2.GetPixel(i, j); Color pixO = BitmapOrigin.GetPixel(i, j); color[0, i, j] = (int)(pixR.R * c1 - pixO.R * c); color[1, i, j] = (int)(pixR.G * c1 - pixO.G * c); color[2, i, j] = (int)(pixR.B * c1 - pixO.B * c); } } for (int i = start; i < x - start; i++) { for (int j = start; j < y - start; j++) { for (int c = 0; c < 3; c++) { color[c, i, j] = color[c, i, j] > 255 ? 255 : color[c, i, j]; color[c, i, j] = color[c, i, j] < 0 ? 0 : color[c, i, j]; } } } //color = RealBD(color); bitmapResult = new Bitmap(x, y); for (int i = start; i < x - start; i++) { for (int j = start; j < y - start; j++) { bitmapResult.SetPixel(i, j, Color.FromArgb(color[0, i, j], color[1, i, j], color[2, i, j])); } } }
private void Math_MultiEvent() { if (BitmapOrigin.Size != BitmapO2.Size) { return; } x = BitmapO2.Width; y = BitmapO2.Height; bitmapResult = new Bitmap(x, y); for (int i = 0; i < bitmapResult.Width; i++) { for (int j = 0; j < bitmapResult.Height; j++) { var colorO = BitmapOrigin.GetPixel(i, j); var colorR = BitmapO2.GetPixel(i, j); int r = colorO.R * colorR.R / 255; int g = colorO.G * colorR.G / 255; int b = colorO.B * colorR.B / 255; bitmapResult.SetPixel(i, j, Color.FromArgb(r, g, b)); } } }