public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); for (int x = 0; x < ProcessingImage.Width; ++x) { for (int y = 0; y < ProcessingImage.Height; ++y) { SKColor color = ProcessingImage.GetPixel(x, y); double grayscale = color.Red * 0.3 + color.Green * 0.59 + color.Blue * 0.11; byte value = (byte)grayscale; ProcessedImage.SetPixel(x, y, new SKColor(value, value, value, color.Alpha)); } } }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); for (int x = 0; x < ProcessingImage.Width; x++) { for (int y = 0; y < ProcessingImage.Height; y++) { SKColor pixel = ProcessingImage.GetPixel(x, y); if (x == 0 || y == 0 || x == ProcessingImage.Width - 1 || y == ProcessingImage.Height - 1) { ProcessedImage.SetPixel(x, y, pixel); } else { // 3x3 mask List <byte> mask = new List <byte> { ProcessingImage.GetPixel(x - 1, y - 1).Red, ProcessingImage.GetPixel(x - 1, y).Red, ProcessingImage.GetPixel(x - 1, y + 1).Red, ProcessingImage.GetPixel(x, y - 1).Red, ProcessingImage.GetPixel(x, y).Red, ProcessingImage.GetPixel(x, y + 1).Red, ProcessingImage.GetPixel(x + 1, y - 1).Red, ProcessingImage.GetPixel(x + 1, y).Red, ProcessingImage.GetPixel(x + 1, y + 1).Red }; byte average = 0; foreach (byte px in mask) { average += px; } average /= 9; ProcessedImage.SetPixel(x, y, new SKColor(average, average, average, pixel.Alpha)); } } } }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Info); for (int x = 0; x < ProcessingImage.Width; x++) { for (int y = 0; y < ProcessingImage.Height; y++) { SKColor pixel = ProcessingImage.GetPixel(x, y); float distance = (float)Math.Sqrt( ((int)pixel.Red - (int)Color.Red) * ((int)pixel.Red - (int)Color.Red) + ((int)pixel.Green - (int)Color.Green) * ((int)pixel.Green - (int)Color.Green) + ((int)pixel.Blue - (int)Color.Blue) * ((int)pixel.Blue - (int)Color.Blue) ); ProcessedImage.SetPixel(x, y, distance <= EstimatedDistance ? new SKColor(0, 0, 0, pixel.Alpha) : new SKColor(255, 255, 255, pixel.Alpha)); } } }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); for (int x = 0; x < ProcessingImage.Width; x++) { for (int y = 0; y < ProcessingImage.Height; y++) { SKColor pixel = ProcessingImage.GetPixel(x, y); if (x == 0 || y == 0 || x == ProcessingImage.Width - 1 || y == ProcessingImage.Height - 1) { ProcessedImage.SetPixel(x, y, pixel); } else { // 3x3 mask List <byte> mask = new List <byte> { ProcessingImage.GetPixel(x - 1, y - 1).Red, ProcessingImage.GetPixel(x - 1, y).Red, ProcessingImage.GetPixel(x - 1, y + 1).Red, ProcessingImage.GetPixel(x, y - 1).Red, ProcessingImage.GetPixel(x, y).Red, ProcessingImage.GetPixel(x, y + 1).Red, ProcessingImage.GetPixel(x + 1, y - 1).Red, ProcessingImage.GetPixel(x + 1, y).Red, ProcessingImage.GetPixel(x + 1, y + 1).Red }; mask.Sort(); ProcessedImage.SetPixel(x, y, new SKColor(mask[4], mask[4], mask[4], pixel.Alpha)); } } } }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); double[] GreyLevels = new double[256]; double GlSum = 0; for (int x = 0; x < ProcessingImage.Width; x++) { for (int y = 0; y < ProcessingImage.Height; y++) { SKColor pixel = ProcessingImage.GetPixel(x, y); if (pixel.Alpha != 0) { GreyLevels[pixel.Red] += 1; } } } for (int index = 0; index < 256; index++) { GreyLevels[index] /= (ProcessingImage.Width * ProcessingImage.Height); GlSum += GreyLevels[index]; } double FirstClassProb, SecondClassProb; double FirstClassMean, SecondClassMean, MeanGrey; double FirstSigma, SecondSigma, MaxSigma = 0; double zwSigma, imSigma; int BestThreshold = 0; for (int Threshold = 1; Threshold < 255; Threshold++) { FirstClassMean = 0; SecondClassMean = 0; FirstClassProb = 0; SecondClassProb = 0; FirstSigma = 0; SecondSigma = 0; for (int index = 0; index <= Threshold; index++) { FirstClassProb += GreyLevels[index]; } SecondClassProb = GlSum - FirstClassProb; for (int index = 0; index < 256; index++) { if (index <= Threshold) { FirstClassMean += index * GreyLevels[index]; } else { SecondClassMean += index * GreyLevels[index]; } } FirstClassMean = ((double)1 / FirstClassProb) * FirstClassMean; SecondClassMean = ((double)1 / SecondClassProb) * SecondClassMean; MeanGrey = FirstClassMean * FirstClassProb + SecondClassProb * SecondClassMean; for (int index = 0; index < 256; index++) { if (index <= Threshold) { FirstSigma += GreyLevels[index] * System.Math.Pow(index - FirstClassMean, 2); } else { SecondSigma += GreyLevels[index] * System.Math.Pow(index - SecondClassMean, 2); } } zwSigma = FirstClassProb * System.Math.Pow(FirstClassMean - MeanGrey, 2) + SecondClassProb * System.Math.Pow(SecondClassMean - MeanGrey, 2); imSigma = FirstClassProb * FirstSigma + SecondClassProb * SecondSigma; double val = zwSigma / imSigma; if (val > MaxSigma) { MaxSigma = val; BestThreshold = Threshold; } } for (int y = 0; y < ProcessingImage.Height; y++) { for (int x = 0; x < ProcessingImage.Width; x++) { SKColor pixel = ProcessingImage.GetPixel(x, y); if (pixel.Red >= BestThreshold) { ProcessedImage.SetPixel(x, y, new SKColor(255, 255, 255, pixel.Alpha)); } else { ProcessedImage.SetPixel(x, y, new SKColor(0, 0, 0, pixel.Alpha)); } } } }
public void Execute() { ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height); int sigma = 1; double constant = 1d / (2 * Math.PI * sigma * sigma); for (int y = sigma; y < ProcessingImage.Height - sigma; y++) { for (int x = sigma; x < ProcessingImage.Width - sigma; x++) { double suma = 0, distanta = 0, sumBeforeDivide = 0; for (int i = -sigma; i <= sigma; i++) { for (int j = -sigma; j <= sigma; j++) { distanta = ((i * i) + (j * j)) / (2 * sigma * sigma); sumBeforeDivide = sumBeforeDivide + ProcessingImage.GetPixel(x + i, y + i).Red *(constant * Math.Exp(-distanta)); suma = suma + constant * Math.Exp(-distanta); } } for (int i = -sigma; i <= sigma; i++) { for (int j = -sigma; j <= sigma; j++) { byte value = (byte)(sumBeforeDivide / suma); ProcessedImage.SetPixel(x, y, new SKColor(value, value, value)); } } } } for (int y = 0; y < sigma; y++) { for (int x = 0; x < ProcessingImage.Width; x++) { ProcessedImage.SetPixel(x, y, ProcessingImage.GetPixel(x, y)); ProcessedImage.SetPixel(ProcessingImage.Width - x - 1, y, ProcessingImage.GetPixel(ProcessingImage.Width - x - 1, y)); } } for (int y = ProcessingImage.Height - sigma; y < ProcessingImage.Height; y++) { for (int x = 0; x < ProcessingImage.Width; x++) { ProcessedImage.SetPixel(x, y, ProcessingImage.GetPixel(x, y)); ProcessedImage.SetPixel(ProcessingImage.Width - x - 1, y, ProcessingImage.GetPixel(ProcessingImage.Width - x - 1, y)); } } for (int y = 0; y < ProcessingImage.Height; y++) { for (int x = 0; x < sigma; x++) { ProcessedImage.SetPixel(x, y, ProcessingImage.GetPixel(x, y)); ProcessedImage.SetPixel(ProcessingImage.Width - x - 1, y, ProcessingImage.GetPixel(ProcessingImage.Width - x - 1, y)); } } for (int y = 0; y < ProcessingImage.Height; y++) { for (int x = ProcessingImage.Width - sigma; x < ProcessingImage.Width; x++) { ProcessedImage.SetPixel(x, y, ProcessingImage.GetPixel(x, y)); ProcessedImage.SetPixel(ProcessingImage.Width - x - 1, y, ProcessingImage.GetPixel(ProcessingImage.Width - x - 1, y)); } } }