private Color[,] dilatationGray(Color[,] Image, StructElement structElement) { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image //Color[,] Image = new Color[InputImage.Size.Width, InputImage.Size.Height]; // Create array to speed-up operations (Bitmap functions are very slow) Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height]; int[,] structMatrix = structElement.getMatrix(); for (int i = 0; i < InputImage.Size.Width; i++) { for (int j = 0; j < InputImage.Size.Height; j++) { output[i, j] = Color.FromArgb(255, 255, 255); } } int offset = (structElement.getSize() - 1) / 2; //convertImageToString(Image); setupProgressBar(); int value = 0; for (int u = offset; u < InputImage.Size.Width - offset; u++) { for (int v = offset; v < InputImage.Size.Height - offset; v++) { value = 0; for (int i = -offset; i < offset; i++) { for (int j = -offset; j < offset; j++) { if (structMatrix[i + offset, j + offset] != -256) //cell off { if (Image[u + i, v + j].R + structMatrix[i + offset, j + offset] > 255) { value = Math.Max(value, 255); } else { value = Math.Max(value, (Image[u + i, v + j].R) + (structMatrix[i + offset, j + offset])); } } } } output[u, v] = Color.FromArgb(value, value, value); progressBar.PerformStep(); } } return(output); }
private Color[,] geodesicDilatationGray(Color[,] Image, StructElement structElement, Bitmap controlImage) { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image Color[,] controlImagee = new Color[InputImage2.Size.Width, InputImage2.Size.Height]; int[,] structMatrix = structElement.getMatrix(); Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height]; convertImageToString2(controlImagee); output = dilatationGray(Image, structElement); output = myApplyMin(output, controlImagee); return(output); }
private Color[,] dilatationBinary(Color[,] Image, StructElement structElement) { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height]; setupProgressBar(); int[,] H = structElement.getMatrix(); int Hsize = structElement.getSize(); for (int i = 0; i < InputImage.Size.Width; i++) { for (int j = 0; j < InputImage.Size.Height; j++) { output[i, j] = Color.FromArgb(255, 255, 255); } } for (int i = 0; i < Hsize; i++) { for (int j = 0; j < Hsize; j++) { if (H[i, j] == 1) { for (int u = 0; u < InputImage.Size.Width - Hsize; u++) { for (int v = 0; v < InputImage.Size.Height - Hsize; v++) { if (Image[u, v].R == 0) { output[u + i, v + j] = Color.FromArgb(0, 0, 0); } } } } } } return(output); }
private Color[,] erosion(Bitmap InputImage, StructElement structElement, Bitmap controlImage) // To adjust { if (OutputImage != null) { OutputImage.Dispose(); // Reset output image } OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image Color[,] Image = new Color[InputImage.Size.Width, InputImage.Size.Height]; // Create array to speed-up operations (Bitmap functions are very slow) Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height]; int[,] structMatrix = structElement.getMatrix(); convertImageToString(Image); setupProgressBar(); if (isBinary(Image, InputImage.Size.Width, InputImage.Size.Height)) { MessageBox.Show("Binary!"); if (controlImage == null) { output = erosionBinary(Image, structElement); MessageBox.Show("Binary Erosion!"); } else { output = geodesicErosionBinary(Image, structElement, controlImage); } } else { if (controlImage == null) { output = erosionGray(Image, structElement); } else { output = geodesicErosionGray(Image, structElement, controlImage); } } return(output); }