private void showBand_res(Bitmap img) { // show RGB bands Tuple <int[, , ], int[, , ], int[, , ]> bands = ImageRW.getBand(img); pictureBox_resultRB.Image = ImageRW.SetRGB(bands.Item1); pictureBox_resultGB.Image = ImageRW.SetRGB(bands.Item2); pictureBox_resultBB.Image = ImageRW.SetRGB(bands.Item3); // show histogram of RGB bands Tuple <Bitmap, Bitmap, Bitmap> histograms = ImageRW.getHistogram(img); pictureBox_resultRH.Image = histograms.Item1; pictureBox_resultGH.Image = histograms.Item2; pictureBox_resultBH.Image = histograms.Item3; }
public static Bitmap Transform(Bitmap img, string str1) { int[,,] rgb = ImageRW.GetRGB(img); int height = rgb.GetLength(0); int width = rgb.GetLength(1); switch (str1) { case "Negative": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { rgb[j, i, 0] = 255 - rgb[j, i, 0]; rgb[j, i, 1] = 255 - rgb[j, i, 1]; rgb[j, i, 2] = 255 - rgb[j, i, 2]; } } break; case "Log-Transform": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { double c = 100; rgb[j, i, 0] = (int)(c * Math.Log(1 + rgb[j, i, 0], 10)); rgb[j, i, 1] = (int)(c * Math.Log(1 + rgb[j, i, 1], 10)); rgb[j, i, 2] = (int)(c * Math.Log(1 + rgb[j, i, 2], 10)); } } break; } img = ImageRW.SetRGB(rgb); return(img); }
public static Bitmap Transform(Bitmap img, string str1) { int[,,] rgb = ImageRW.GetRGB(img); int height = rgb.GetLength(0); int width = rgb.GetLength(1); int[,,] rgb_big = new int[height + 2, width + 2, 3]; int[] values = new int[9]; for (int j = 0; j < height + 2; j++) { for (int i = 0; i < width + 2; i++) { if (j == 0 || i == 0 || j == height + 1 || i == width + 1) { rgb_big[j, i, 0] = 0; rgb_big[j, i, 1] = 0; rgb_big[j, i, 2] = 0; } else { rgb_big[j, i, 0] = rgb[j - 1, i - 1, 0]; rgb_big[j, i, 1] = rgb[j - 1, i - 1, 1]; rgb_big[j, i, 2] = rgb[j - 1, i - 1, 2]; } } } switch (str1) { case "Laplacian(4)": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { values[0] = rgb_big[j, i, k]; values[1] = rgb_big[j, i + 1, k]; values[2] = rgb_big[j, i + 2, k]; values[3] = rgb_big[j + 1, i, k]; values[4] = rgb_big[j + 1, i + 1, k]; values[5] = rgb_big[j + 1, i + 2, k]; values[6] = rgb_big[j + 2, i, k]; values[7] = rgb_big[j + 2, i + 1, k]; values[8] = rgb_big[j + 2, i + 2, k]; Array.Sort(values); rgb[j, i, k] = values[4]; } } } break; case "Mean": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { values[0] = rgb_big[j, i, k]; values[1] = rgb_big[j, i + 1, k]; values[2] = rgb_big[j, i + 2, k]; values[3] = rgb_big[j + 1, i, k]; values[4] = rgb_big[j + 1, i + 1, k]; values[5] = rgb_big[j + 1, i + 2, k]; values[6] = rgb_big[j + 2, i, k]; values[7] = rgb_big[j + 2, i + 1, k]; values[8] = rgb_big[j + 2, i + 2, k]; rgb[j, i, k] = values.Sum() / 9; } } } break; case "Min": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { values[0] = rgb_big[j, i, k]; values[1] = rgb_big[j, i + 1, k]; values[2] = rgb_big[j, i + 2, k]; values[3] = rgb_big[j + 1, i, k]; values[4] = rgb_big[j + 1, i + 1, k]; values[5] = rgb_big[j + 1, i + 2, k]; values[6] = rgb_big[j + 2, i, k]; values[7] = rgb_big[j + 2, i + 1, k]; values[8] = rgb_big[j + 2, i + 2, k]; rgb[j, i, k] = values.Min(); } } } break; case "Max": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { values[0] = rgb_big[j, i, k]; values[1] = rgb_big[j, i + 1, k]; values[2] = rgb_big[j, i + 2, k]; values[3] = rgb_big[j + 1, i, k]; values[4] = rgb_big[j + 1, i + 1, k]; values[5] = rgb_big[j + 1, i + 2, k]; values[6] = rgb_big[j + 2, i, k]; values[7] = rgb_big[j + 2, i + 1, k]; values[8] = rgb_big[j + 2, i + 2, k]; rgb[j, i, k] = values.Max(); } } } break; } img = ImageRW.SetRGB(rgb); return(img); }
public static Bitmap Transform(Bitmap img, string str1) { int[,,] rgb = ImageRW.GetRGB(img); int height = rgb.GetLength(0); int width = rgb.GetLength(1); int[,,] rgb_big = new int[height + 2, width + 2, 3]; for (int j = 0; j < height + 2; j++) { for (int i = 0; i < width + 2; i++) { if (j == 0 || i == 0 || j == height + 1 || i == width + 1) { rgb_big[j, i, 0] = 0; rgb_big[j, i, 1] = 0; rgb_big[j, i, 2] = 0; } else { rgb_big[j, i, 0] = rgb[j - 1, i - 1, 0]; rgb_big[j, i, 1] = rgb[j - 1, i - 1, 1]; rgb_big[j, i, 2] = rgb[j - 1, i - 1, 2]; } } } switch (str1) { case "Laplacian(4)": int[,] mask = new int[3, 3] { { 0, -1, 0 }, { -1, 4, -1 }, { 0, -1, 0 } }; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { rgb[j, i, k] = rgb_big[j, i, k] * mask[0, 0] + rgb_big[j, i + 1, k] * mask[0, 1] + rgb_big[j, i + 2, k] * mask[0, 2] + rgb_big[j + 1, i, k] * mask[1, 0] + rgb_big[j + 1, i + 1, k] * mask[1, 1] + rgb_big[j + 1, i + 2, k] * mask[1, 2] + rgb_big[j + 2, i, k] * mask[2, 0] + rgb_big[j + 2, i + 1, k] * mask[2, 1] + rgb_big[j + 2, i + 2, k] * mask[2, 2]; if (rgb[j, i, k] > 255) { rgb[j, i, k] = 255; } if (rgb[j, i, k] < 0) { rgb[j, i, k] = 0; } } } } break; case "Laplacian(4) Add": mask = new int[3, 3] { { 0, -1, 0 }, { -1, 4, -1 }, { 0, -1, 0 } }; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { rgb[j, i, k] = rgb[j, i, k] + ( rgb_big[j, i, k] * mask[0, 0] + rgb_big[j, i + 1, k] * mask[0, 1] + rgb_big[j, i + 2, k] * mask[0, 2] + rgb_big[j + 1, i, k] * mask[1, 0] + rgb_big[j + 1, i + 1, k] * mask[1, 1] + rgb_big[j + 1, i + 2, k] * mask[1, 2] + rgb_big[j + 2, i, k] * mask[2, 0] + rgb_big[j + 2, i + 1, k] * mask[2, 1] + rgb_big[j + 2, i + 2, k] * mask[2, 2] ); if (rgb[j, i, k] > 255) { rgb[j, i, k] = 255; } if (rgb[j, i, k] < 0) { rgb[j, i, k] = 0; } } } } break; case "Laplacian(4) Minus": mask = new int[3, 3] { { 0, -1, 0 }, { -1, 4, -1 }, { 0, -1, 0 } }; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { rgb[j, i, k] = rgb[j, i, k] - ( rgb_big[j, i, k] * mask[0, 0] + rgb_big[j, i + 1, k] * mask[0, 1] + rgb_big[j, i + 2, k] * mask[0, 2] + rgb_big[j + 1, i, k] * mask[1, 0] + rgb_big[j + 1, i + 1, k] * mask[1, 1] + rgb_big[j + 1, i + 2, k] * mask[1, 2] + rgb_big[j + 2, i, k] * mask[2, 0] + rgb_big[j + 2, i + 1, k] * mask[2, 1] + rgb_big[j + 2, i + 2, k] * mask[2, 2] ); if (rgb[j, i, k] > 255) { rgb[j, i, k] = 255; } if (rgb[j, i, k] < 0) { rgb[j, i, k] = 0; } } } } break; case "Laplacian(9)": mask = new int[3, 3] { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } }; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { rgb[j, i, k] = rgb_big[j, i, k] * mask[0, 0] + rgb_big[j, i + 1, k] * mask[0, 1] + rgb_big[j, i + 2, k] * mask[0, 2] + rgb_big[j + 1, i, k] * mask[1, 0] + rgb_big[j + 1, i + 1, k] * mask[1, 1] + rgb_big[j + 1, i + 2, k] * mask[1, 2] + rgb_big[j + 2, i, k] * mask[2, 0] + rgb_big[j + 2, i + 1, k] * mask[2, 1] + rgb_big[j + 2, i + 2, k] * mask[2, 2]; if (rgb[j, i, k] > 255) { rgb[j, i, k] = 255; } if (rgb[j, i, k] < 0) { rgb[j, i, k] = 0; } } } } break; case "Laplacian(9) Add": mask = new int[3, 3] { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } }; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { rgb[j, i, k] = rgb[j, i, k] + ( rgb_big[j, i, k] * mask[0, 0] + rgb_big[j, i + 1, k] * mask[0, 1] + rgb_big[j, i + 2, k] * mask[0, 2] + rgb_big[j + 1, i, k] * mask[1, 0] + rgb_big[j + 1, i + 1, k] * mask[1, 1] + rgb_big[j + 1, i + 2, k] * mask[1, 2] + rgb_big[j + 2, i, k] * mask[2, 0] + rgb_big[j + 2, i + 1, k] * mask[2, 1] + rgb_big[j + 2, i + 2, k] * mask[2, 2] ); if (rgb[j, i, k] > 255) { rgb[j, i, k] = 255; } if (rgb[j, i, k] < 0) { rgb[j, i, k] = 0; } } } } break; case "Laplacian(9) Minus": mask = new int[3, 3] { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } }; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { rgb[j, i, k] = rgb[j, i, k] - ( rgb_big[j, i, k] * mask[0, 0] + rgb_big[j, i + 1, k] * mask[0, 1] + rgb_big[j, i + 2, k] * mask[0, 2] + rgb_big[j + 1, i, k] * mask[1, 0] + rgb_big[j + 1, i + 1, k] * mask[1, 1] + rgb_big[j + 1, i + 2, k] * mask[1, 2] + rgb_big[j + 2, i, k] * mask[2, 0] + rgb_big[j + 2, i + 1, k] * mask[2, 1] + rgb_big[j + 2, i + 2, k] * mask[2, 2] ); if (rgb[j, i, k] > 255) { rgb[j, i, k] = 255; } if (rgb[j, i, k] < 0) { rgb[j, i, k] = 0; } } } } break; case "Sobel": int[,] mask_gx = new int[3, 3] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; int[,] mask_gy = new int[3, 3] { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } }; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { for (int k = 0; k < 3; k++) { int gx = rgb_big[j, i, k] * mask_gx[0, 0] + rgb_big[j, i + 1, k] * mask_gx[0, 1] + rgb_big[j, i + 2, k] * mask_gx[0, 2] + rgb_big[j + 1, i, k] * mask_gx[1, 0] + rgb_big[j + 1, i + 1, k] * mask_gx[1, 1] + rgb_big[j + 1, i + 2, k] * mask_gx[1, 2] + rgb_big[j + 2, i, k] * mask_gx[2, 0] + rgb_big[j + 2, i + 1, k] * mask_gx[2, 1] + rgb_big[j + 2, i + 2, k] * mask_gx[2, 2]; int gy = rgb_big[j, i, k] * mask_gy[0, 0] + rgb_big[j, i + 1, k] * mask_gy[0, 1] + rgb_big[j, i + 2, k] * mask_gy[0, 2] + rgb_big[j + 1, i, k] * mask_gy[1, 0] + rgb_big[j + 1, i + 1, k] * mask_gy[1, 1] + rgb_big[j + 1, i + 2, k] * mask_gy[1, 2] + rgb_big[j + 2, i, k] * mask_gy[2, 0] + rgb_big[j + 2, i + 1, k] * mask_gy[2, 1] + rgb_big[j + 2, i + 2, k] * mask_gy[2, 2]; rgb[j, i, k] = (int)Math.Sqrt(Math.Pow(gx, 2) + Math.Pow(gy, 2)); if (rgb[j, i, k] > 255) { rgb[j, i, k] = 255; } } } } break; } img = ImageRW.SetRGB(rgb); return(img); }
public static Bitmap Transform(Bitmap img, string str1) { int[,,] rgb = ImageRW.GetRGB(img); int height = rgb.GetLength(0); int width = rgb.GetLength(1); switch (str1) { case "Mean-Value": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { int gray = (rgb[j, i, 0] + rgb[j, i, 1] + rgb[j, i, 2]) / 3; rgb[j, i, 0] = gray; rgb[j, i, 1] = gray; rgb[j, i, 2] = gray; } } break; case "Mean-Weight": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { float gray = (float)(0.299 * rgb[j, i, 0] + 0.587 * rgb[j, i, 1] + 0.114 * rgb[j, i, 2]); rgb[j, i, 0] = (int)gray; rgb[j, i, 1] = (int)gray; rgb[j, i, 2] = (int)gray; } } break; case "Maximum": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { int gray = Math.Max(rgb[j, i, 0], rgb[j, i, 1]); gray = Math.Max(gray, rgb[j, i, 2]); rgb[j, i, 0] = gray; rgb[j, i, 1] = gray; rgb[j, i, 2] = gray; } } break; case "Negative": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { rgb[j, i, 0] = 255 - rgb[j, i, 0]; rgb[j, i, 1] = 255 - rgb[j, i, 1]; rgb[j, i, 2] = 255 - rgb[j, i, 2]; } } break; case "Log-Transform": for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { double c = 100; rgb[j, i, 0] = (int)(c * Math.Log(1 + rgb[j, i, 0], 10)); rgb[j, i, 1] = (int)(c * Math.Log(1 + rgb[j, i, 1], 10)); rgb[j, i, 2] = (int)(c * Math.Log(1 + rgb[j, i, 2], 10)); } } break; //case "Power-Law": // for (int j = 0; j < height; j++) // { // for (int i = 0; i < width; i++) // { // double c = 255; // double gamma = 1; // if (str2 == "gamma=2.5") // { // gamma = 2.5; // } // else if (str2 == "gamma=0.4") // { // gamma = 0.4; // } // rgb[j, i, 0] = (int)(c * Math.Pow(((double)rgb[j, i, 0]) / 255, gamma)); // rgb[j, i, 1] = (int)(c * Math.Pow(((double)rgb[j, i, 1]) / 255, gamma)); // rgb[j, i, 2] = (int)(c * Math.Pow(((double)rgb[j, i, 2]) / 255, gamma)); // } // } // break; } img = ImageRW.SetRGB(rgb); return(img); }