protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { double redX = 0.0, greenX = 0.0, blueX = 0.0; double redY = 0.0, greenY = 0.0, blueY = 0.0; for (int i = -radius; i <= radius; ++i) { for (int j = -radius; j <= radius; ++j) { int idX = BorderProcessing(x + j, 0, width - 1); int idY = BorderProcessing(y + i, 0, height - 1); redX += wrapImage[idX, idY].R * kernelX[j + radius, i + radius] * 1 / 2; greenX += wrapImage[idX, idY].G * kernelX[j + radius, i + radius] * 1 / 2; blueX += wrapImage[idX, idY].B * kernelX[j + radius, i + radius] * 1 / 2; redY += wrapImage[idX, idY].R * kernelY[j + radius, i + radius] * 1 / 2; greenY += wrapImage[idX, idY].G * kernelY[j + radius, i + radius] * 1 / 2; blueY += wrapImage[idX, idY].B * kernelY[j + radius, i + radius] * 1 / 2; } } double gxx, gyy, gxy; gxx = Math.Pow(redX, 2) + Math.Pow(greenX, 2) + Math.Pow(blueX, 2); gyy = Math.Pow(redY, 2) + Math.Pow(greenY, 2) + Math.Pow(blueY, 2); gxy = redX * redY + greenX * greenY + blueX * blueY; double angle = 0.5 * Math.Atan(2 * gxy / Math.Abs(gxx - gyy)); int result = Clamp((int)Math.Sqrt(0.5 * (gxx + gyy + Math.Abs(gxx - gyy) * Math.Cos(2 * angle) + 2 * gxy * Math.Sin(2 * angle))), 0, 255); return(Color.FromArgb(result, result, result)); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { double redX = 0, greenX = 0, blueX = 0; double redY = 0, greenY = 0, blueY = 0; for (int i = -radius; i <= radius; ++i) { for (int j = -radius; j <= radius; ++j) { int idX = BorderProcessing(x + j, 0, width - 1); int idY = BorderProcessing(y + i, 0, height - 1); redX += wrapImage[idX, idY].R * kernelX[j + radius, i + radius]; greenX += wrapImage[idX, idY].G * kernelX[j + radius, i + radius]; blueX += wrapImage[idX, idY].B * kernelX[j + radius, i + radius]; redY += wrapImage[idX, idY].R * kernelY[j + radius, i + radius]; greenY += wrapImage[idX, idY].G * kernelY[j + radius, i + radius]; blueY += wrapImage[idX, idY].B * kernelY[j + radius, i + radius]; } } int result = Clamp((int)( (Math.Sqrt(redX * redX + redY * redY) + Math.Sqrt(greenX * greenX + greenY * greenY) + Math.Sqrt(blueX * blueX + blueY * blueY)) / 3), 0, 255); return(Color.FromArgb(result, result, result)); }
public virtual Bitmap ProcessImage(Bitmap sourceImage, BackgroundWorker worker) { Bitmap resultImage = new Bitmap(sourceImage); width = resultImage.Width; height = resultImage.Height; int checkProgress = -1; using (ImageWrapper wrapImage = new ImageWrapper(resultImage)) { for (int i = 0; i < height; ++i) { if (i > checkProgress) { worker.ReportProgress((int)((double)i / height * 100)); if (worker.CancellationPending) { return(null); } checkProgress += 100; } for (int j = 0; j < width; ++j) { wrapImage[j, i] = CalculateNewPixelColor(wrapImage, j, i); } } } return(resultImage); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { double red = 1.0; double green = 1.0; double blue = 1.0; for (int i = -radius; i <= radius; ++i) { for (int j = -radius; j <= radius; ++j) { int idX = BorderProcessing(x + j, 0, width - 1); int idY = BorderProcessing(y + i, 0, height - 1); red *= wrapImage[idX, idY].R; green *= wrapImage[idX, idY].G; blue *= wrapImage[idX, idY].B; } } red = Math.Pow(red, 1.0 / (diameter * diameter)); green = Math.Pow(green, 1.0 / (diameter * diameter)); blue = Math.Pow(blue, 1.0 / (diameter * diameter)); return(Color.FromArgb((int)red, (int)green, (int)blue)); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { int[] red = new int[diameter * diameter]; int[] green = new int[diameter * diameter]; int[] blue = new int[diameter * diameter]; int middle = (diameter * diameter + 1) / 2; int currentIndex = 0; for (int i = -radius; i <= radius; ++i) { for (int j = -radius; j <= radius; ++j) { int idX = BorderProcessing(x + j, 0, width - 1); int idY = BorderProcessing(y + i, 0, height - 1); red[currentIndex] = wrapImage[idX, idY].R; green[currentIndex] = wrapImage[idX, idY].G; blue[currentIndex] = wrapImage[idX, idY].B; ++currentIndex; } } Array.Sort(red); Array.Sort(green); Array.Sort(blue); return(Color.FromArgb(red[middle], green[middle], blue[middle])); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { double red = 0.0; double green = 0.0; double blue = 0.0; for (int i = -radius; i <= radius; ++i) { for (int j = -radius; j <= radius; ++j) { int idX = BorderProcessing(x + j, 0, width - 1); int idY = BorderProcessing(y + i, 0, height - 1); red += 1.0 / wrapImage[idX, idY].R; green += 1.0 / wrapImage[idX, idY].G; blue += 1.0 / wrapImage[idX, idY].B; } } red = (diameter * diameter) / red; green = (diameter * diameter) / green; blue = (diameter * diameter) / blue; return(Color.FromArgb((int)red, (int)green, (int)blue)); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { double red = 0.0; double green = 0.0; double blue = 0.0; for (int i = -radius; i <= radius; ++i) { for (int j = -radius; j <= radius; ++j) { int idX = BorderProcessing(x + j, 0, width - 1); int idY = BorderProcessing(y + i, 0, height - 1); red += wrapImage[idX, idY].R * kernel[j + radius, i + radius]; green += wrapImage[idX, idY].G * kernel[j + radius, i + radius]; blue += wrapImage[idX, idY].B * kernel[j + radius, i + radius]; } } red = Clamp((int)red, 0, 255); green = Clamp((int)green, 0, 255); blue = Clamp((int)blue, 0, 255); return(Color.FromArgb((int)red, (int)green, (int)blue)); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { int red = wrapImage[x, y].R; int green = wrapImage[x, y].G; int blue = wrapImage[x, y].B; int result = (red + green + blue) / 3; return(Color.FromArgb(result, result, result)); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { int randNumber = (int)(leftValue + randomValue.NextDouble() * constant); int red = Clamp(wrapImage[x, y].R + randNumber, 0, 255); int green = Clamp(wrapImage[x, y].G + randNumber, 0, 255); int blue = Clamp(wrapImage[x, y].B + randNumber, 0, 255); return(Color.FromArgb(red, green, blue)); }
public override Bitmap ProcessImage(Bitmap sourceImage, BackgroundWorker worker) { this.width = sourceImage.Width; this.height = sourceImage.Height; Bitmap resultImage = new Bitmap(sourceImage); Bitmap tempBitmap = new Bitmap(width, height); int checkProgress = -1; using (ImageWrapper wrapTempImage = new ImageWrapper(tempBitmap)) { foreach (var point in wrapTempImage) { wrapTempImage[point] = Color.White; } } Pepper pepper = new Pepper(percent); Erosion erosion = new Erosion(diameter, kernel); tempBitmap = erosion.ProcessImage(pepper.ProcessImage(tempBitmap, worker), worker); using (ImageWrapper wrapTempImage = new ImageWrapper(tempBitmap)) { using (ImageWrapper wrapImage = new ImageWrapper(resultImage, true)) { for (int i = 0; i < height; ++i) { if (i > checkProgress) { worker.ReportProgress((int)((double)i / resultImage.Height * 100)); if (worker.CancellationPending) { return(null); } checkProgress += 100; } for (int j = 0; j < width; ++j) { Color neighborColor = wrapTempImage[j, i]; if (neighborColor.R == 0 && neighborColor.G == 0 && neighborColor.B == 0) { wrapImage[j, i] = wrapTempImage[j, i]; } } } } } return(resultImage); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { int currentPercent = (int)(randomValue.NextDouble() * 100); if (0 <= currentPercent && currentPercent < pepperPercent) { return(Color.FromArgb(0, 0, 0)); } return(wrapImage[x, y]); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { double u1 = 1.0 - randomValue.NextDouble(); double u2 = 1.0 - randomValue.NextDouble(); double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); double randNormal = middle + sigma * randStdNormal; int red = Clamp((int)(wrapImage[x, y].R + randNormal), 0, 255); int green = Clamp((int)(wrapImage[x, y].G + randNormal), 0, 255); int blue = Clamp((int)(wrapImage[x, y].B + randNormal), 0, 255); return(Color.FromArgb(red, green, blue)); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { int min = 255; Color resultColor = Color.White; for (int i = -radius; i <= radius; ++i) { for (int j = -radius; j <= radius; ++j) { int idX = BorderProcessing(x + j, 0, width - 1); int idY = BorderProcessing(y + i, 0, height - 1); int intensity = (wrapImage[idX, idY].R + wrapImage[idX, idY].G + wrapImage[idX, idY].B) / 3; if ((kernel[j + radius, i + radius] > 0) && (intensity < min)) { min = intensity; resultColor = wrapImage[idX, idY]; } } } return(resultColor); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { double red = 0.0; double green = 0.0; double blue = 0.0; double numeratorR = 0.0; double numeratorG = 0.0; double numeratorB = 0.0; double denomiratorR = 0.0; double denomiratorG = 0.0; double denomiratorB = 0.0; for (int i = -radius; i <= radius; ++i) { for (int j = -radius; j <= radius; ++j) { int idX = BorderProcessing(x + j, 0, width - 1); int idY = BorderProcessing(y + i, 0, height - 1); numeratorR += Math.Pow(wrapImage[idX, idY].R, order + 1); numeratorG += Math.Pow(wrapImage[idX, idY].G, order + 1); numeratorB += Math.Pow(wrapImage[idX, idY].B, order + 1); denomiratorR += Math.Pow(wrapImage[idX, idY].R, order); denomiratorG += Math.Pow(wrapImage[idX, idY].G, order); denomiratorB += Math.Pow(wrapImage[idX, idY].B, order); } } red = Clamp((int)(numeratorR / denomiratorR), 0, 255); green = Clamp((int)(numeratorG / denomiratorG), 0, 255); blue = Clamp((int)(numeratorB / denomiratorB), 0, 255); return(Color.FromArgb((int)red, (int)green, (int)blue)); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { int[] red = new int[diameter * diameter]; int[] green = new int[diameter * diameter]; int[] blue = new int[diameter * diameter]; int firstIndex = 0; int lastIndex = diameter * diameter - 1; int currentIndex = 0; for (int i = -radius; i <= radius; ++i) { for (int j = -radius; j <= radius; ++j) { int idX = BorderProcessing(x + j, 0, width - 1); int idY = BorderProcessing(y + i, 0, height - 1); Color neighborColor = wrapImage[idX, idY]; red[currentIndex] = neighborColor.R; green[currentIndex] = neighborColor.G; blue[currentIndex] = neighborColor.B; ++currentIndex; } } Array.Sort(red); Array.Sort(green); Array.Sort(blue); int resultR = (red[firstIndex] + red[lastIndex]) / 2; int resultG = (green[firstIndex] + green[lastIndex]) / 2; int resultB = (blue[firstIndex] + blue[lastIndex]) / 2; return(Color.FromArgb(resultR, resultG, resultB)); }
protected abstract Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y);
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { return(wrapImage[x, y]); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { int red = wrapImage[x, y].R; return(Color.FromArgb(red, red, red)); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { int blue = wrapImage[x, y].B; return(Color.FromArgb(blue, blue, blue)); }
protected override Color CalculateNewPixelColor(ImageWrapper wrapImage, int x, int y) { int green = wrapImage[x, y].G; return(Color.FromArgb(green, green, green)); }