public void ApplyErosionFilter(BinaryMask mask, RGBPixel[,] neighbours) { int size = mask.Size; byte minRed = oldRed, minGreen = oldGreen, minBlue = oldBlue; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (mask.Matrix[i, j]) { RGBPixel neighbour = neighbours[i, j]; if (neighbour.oldRed < minRed) { minRed = neighbour.oldRed; } if (neighbour.oldGreen < minGreen) { minGreen = neighbour.oldGreen; } if (neighbour.oldBlue < minBlue) { minBlue = neighbour.oldBlue; } } } } Red = minRed; Green = minGreen; Blue = minBlue; }
public Tuple <BinaryMask, BinaryMask> SeparateMask() { BinaryMask whiteMask = new BinaryMask(Size); BinaryMask blackMask = new BinaryMask(Size); for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { if (Matrix[i, j] == 1) { whiteMask.Matrix[i, j] = true; blackMask.Matrix[i, j] = false; } else if (Matrix[i, j] == -1) { whiteMask.Matrix[i, j] = false; blackMask.Matrix[i, j] = true; } else { whiteMask.Matrix[i, j] = false; blackMask.Matrix[i, j] = false; } } } return(new Tuple <BinaryMask, BinaryMask>(whiteMask, blackMask)); }
public void ApplyDilationFilter(BinaryMask mask, RGBPixel[,] neighbours) { int size = mask.Size; byte maxRed = oldRed, maxGreen = oldGreen, maxBlue = oldBlue; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (mask.Matrix[i, j]) { RGBPixel neighbour = neighbours[i, j]; if (neighbour.Red > maxRed) { maxRed = neighbour.oldRed; } if (neighbour.Green > maxGreen) { maxGreen = neighbour.oldGreen; } if (neighbour.Blue > maxBlue) { maxBlue = neighbour.oldBlue; } } } } Red = maxRed; Green = maxGreen; Blue = maxBlue; }
public void ClosingOperation(BinaryMask mask) { outBitmap = new WriteableBitmap(originalBitmap); outBitmap.Lock(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { RGBPixel pixel = pixelMatrix[x, y]; RGBPixel[,] neighbours = GetNeighbours(pixel, mask.Size); pixel.ApplyDilationFilter(mask, neighbours); } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixelMatrix[x, y].Update(); } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { RGBPixel pixel = pixelMatrix[x, y]; RGBPixel[,] neighbours = GetNeighbours(pixel, mask.Size); pixel.ApplyErosionFilter(mask, neighbours); DrawPixel(pixel); } } UpdateImage(); UpdatePixelMatrix(); }