//new_pixels is the enlarged photo - use for neighborhood, but write to smaller buffer of original size public AdvColor[,] NoiseReductionThreshold(AdvColor[,] new_pixels, int kernel, int threshold) { AdvColor[,] new_image = new AdvColor[pixels.GetLength(0), pixels.GetLength(1)]; int additions = kernel / 2; for (int i = 0 + additions; i < pixels.GetLength(0) + additions; i++) { for (int j = 0 + additions; j < pixels.GetLength(1) + additions; j++) { List <AdvColor> neighborhood = GetNeighborhood(new_pixels, i, j, kernel); int sum = 0; foreach (AdvColor color in neighborhood) { sum += color.GetColor(ColorPlane.eGreen); } sum /= neighborhood.Count; AdvColor original_pixel = new AdvColor(pixels[i - additions, j - additions], ColorPlane.eGreen); if (Math.Abs(original_pixel.GetColor(ColorPlane.eGreen) - sum) > threshold) { original_pixel = new AdvColor(sum, sum, sum, ColorPlane.eGreen); } new_image[i - additions, j - additions] = original_pixel; } } return(new_image); }
public AdvColor[,] HistogramStretch(AdvColor low, AdvColor high, Histogram histogram, ColorPlane plane) { int height = GetHeight(); int width = GetWidth(); AdvColor[,] new_pixels = new AdvColor[height, width]; int low_color = low.GetColor(plane); int high_color = high.GetColor(plane); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int val = Convert.ToInt32((pixels[i, j].GetColor(plane) - low_color) * (255.0 / (high_color - low_color))); if (val < 0) { val = 0; } if (val > 255) { val = 255; } new_pixels[i, j] = new AdvColor(val, val, val, plane); } } return(new_pixels); }