public object Clone() { var img = EffImage.White(Width, Height); img.pixels = this.pixels.Clone() as Color[, ]; return(img); }
/// <summary> /// 卷积运算 /// </summary> /// <param name="filterMatrix">矩阵</param> /// <param name="factor">因子</param> /// <param name="bias">偏移</param> public void ConvolutionFilter(double[,] filterMatrix, double factor = 1, int bias = 0) { EffImage rt = EffImage.White(width, height); double blue = 0.0; double green = 0.0; double red = 0.0; int filterWidth = filterMatrix.GetLength(1); int filterHeight = filterMatrix.GetLength(0); int filterOffset = (filterWidth - 1) / 2; // TODO : PADDING边角 for (int x = filterOffset; x < Width - filterOffset; x++) { for (int y = filterOffset; y < Height - filterOffset; y++) { blue = green = red = 0d; for (int filterX = -filterOffset; filterX <= filterOffset; filterX++) { for (int filterY = -filterOffset; filterY <= filterOffset; filterY++) { var color = At(x + filterX, y + filterY); red += color.R * filterMatrix[filterY + filterOffset, filterX + filterOffset]; green += color.G * filterMatrix[filterY + filterOffset, filterX + filterOffset]; blue += color.B * filterMatrix[filterY + filterOffset, filterX + filterOffset]; } } red = red * factor + bias; green = green * factor + bias; blue = blue * factor + bias; if (red > 255) { red = 255; } else if (red < 0) { red = 0; } if (green > 255) { green = 255; } else if (green < 0) { green = 0; } if (blue > 255) { blue = 255; } else if (blue < 0) { blue = 0; } rt.Set(x, y, Color.FromArgb((int)red, (int)green, (int)blue)); } } this.pixels = rt.pixels; }