private static RGBPixel[,] Muliply_2_Image(RGBPixel[,] ImageMatrix1, RGBPixel[,] ImageMatrix2) { int Height = ImageOperations.GetHeight(ImageMatrix1); int Width = ImageOperations.GetWidth(ImageMatrix1); RGBPixel[,] mulResult = new RGBPixel[Height, Width]; for (int i = 0; i < Height; i++) { for (int j = 0; j < Width; j++) { mulResult[i, j].red = (byte)(ImageMatrix1[i, j].red * ImageMatrix2[i, j].red); mulResult[i, j].green = (byte)(ImageMatrix1[i, j].green * ImageMatrix2[i, j].green); mulResult[i, j].blue = (byte)(ImageMatrix1[i, j].blue * ImageMatrix2[i, j].blue); } } return(mulResult); }
private static RGBPixel[,] FilterProcess(RGBPixel[,] orignal, FilterType filterType, int PaddingValue) { int Height = ImageOperations.GetHeight(orignal); int Width = ImageOperations.GetWidth(orignal); RGBPixel[,] outputImage = new RGBPixel[(Height - (PaddingValue * 2)), (Width - (PaddingValue * 2))]; //int [,]Mask = new int[3,3]; double[,] Mask = GenetrateMask(filterType); double RMax = InputImageInfo.maxValue; double RMin = InputImageInfo.minValue; for (int i = PaddingValue; i < Width - 1; i++) { for (int j = PaddingValue; j < Height - 1; j++) { double R = 0, G = 0, B = 0; int m = i - PaddingValue; int n = j - PaddingValue; for (int k = 0; k < 3; k++) { for (int z = 0; z < 3; z++) { R += orignal[n + z, m + k].red * Mask[z, k]; G += orignal[n + z, m + k].green * Mask[z, k]; B += orignal[n + z, m + k].blue * Mask[z, k]; } } if (filterType == FilterType.VerticalSobel || filterType == FilterType.HorizontalSobel) { if (R > 255 || G > 255 || B > 255 || R < 0 || G < 0 || B < 0) { outputImage[n, m] = new RGBPixel(0, 0, 0); } else { outputImage[n, m] = new RGBPixel((byte)R, (byte)G, (byte)B); } } else { outputImage[n, m] = new RGBPixel((byte)R, (byte)G, (byte)B); } } } return(outputImage); }
private static RGBPixel[,] Image_Padding(RGBPixel[,] orignal, int kernalsize) { int Height = ImageOperations.GetHeight(orignal); int Width = ImageOperations.GetWidth(orignal); int paddingValue = (kernalsize / 2); RGBPixel[,] paddingImage = new RGBPixel[Height + (paddingValue * 2), Width + (paddingValue * 2)]; int paddingHeight = ImageOperations.GetHeight(paddingImage); int paddingWidth = ImageOperations.GetWidth(paddingImage); for (int i = 0; i < paddingValue; i++) { for (int j = 0; j < paddingWidth; j++) { paddingImage[i, j] = new RGBPixel(0, 0, 0); } for (int j = 0; j < paddingWidth; j++) { paddingImage[Height + i, j] = new RGBPixel(0, 0, 0); } for (int j = 0; j < paddingHeight; j++) { paddingImage[j, i] = new RGBPixel(0, 0, 0); } for (int j = 0; j < paddingHeight; j++) { paddingImage[j, Width + i] = new RGBPixel(0, 0, 0); } } for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { paddingImage[j + paddingValue, i + paddingValue] = orignal[j, i]; } } return(paddingImage); }
private RGBPixel[,] DrawFeature(RGBPixel[,] featurePoints) { int Height = ImageOperations.GetHeight(featurePoints); int Width = ImageOperations.GetWidth(featurePoints); RGBPixel[,] output = new RGBPixel[Height, Width]; for (int i = 0; i < Height; i++) { for (int j = 0; j < Width; j++) { output[i, j] = InputImageInfo.imgCopy[i, j]; if (featurePoints[i, j].red == 1) { output[i, j] = new RGBPixel(0, 5, 255); } } } return(output); }
public static RGBPixel[,] ContrastStretch(RGBPixel[,] ImageMatrix, double B) { int Height = ImageOperations.GetHeight(ImageMatrix); int Width = ImageOperations.GetWidth(ImageMatrix); RGBPixel[,] output = new RGBPixel[Height, Width]; for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { double R = (double)ImageMatrix[j, i].red; double RMax = InputImageInfo.maxValue; double RMin = InputImageInfo.minValue; byte S = (byte)Math.Round(Math.Pow(2, B) * ((R - RMin) / (RMax - RMin))); output[j, i] = new RGBPixel(S, S, S); } } return(output); }
public static RGBPixel[,] Apply_Threshold(RGBPixel[,] ImageMatrix, double threshold) { int Height = ImageOperations.GetHeight(ImageMatrix); int Width = ImageOperations.GetWidth(ImageMatrix); RGBPixel[,] output = new RGBPixel[Height, Width]; for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { double tmp = (double)ImageMatrix[j, i].red; if (tmp >= threshold) { output[j, i] = new RGBPixel(255, 255, 255); } if (tmp < threshold) { output[j, i] = new RGBPixel(0, 0, 0); } } } return(output); }
private static RGBPixel[,] CalculateRresults(RGBPixel[,] R, RGBPixel Rmax, out int count) { count = 0; int Height = ImageOperations.GetHeight(R); int Width = ImageOperations.GetWidth(R); RGBPixel[,] Result = new RGBPixel[Height, Width]; for (int i = 0; i < Height; i++) { for (int j = 0; j < Width; j++) { Result[i, j] = new RGBPixel(0, 0, 0); } } for (int i = 1; i < Height - 1; i++) { for (int j = 1; j < Width - 1; j++) { Result[i, j] = new RGBPixel(0, 0, 0); if (R[i, j].red > 0.1 * Rmax.red && R[i, j].red > R[i - 1, j - 1].red && R[i, j].red > R[i - 1, j].red && R[i, j].red > R[i - 1, j + 1].red && R[i, j].red > R[i, j - 1].red && R[i, j].red > R[i, j + 1].red && R[i, j].red > R[i + 1, j - 1].red && R[i, j].red > R[i + 1, j].red && R[i, j].red > R[i + 1, j + 1].red) { Result[i, j].red = 1; } if (R[i, j].green > 0.1 * Rmax.green && R[i, j].green > R[i - 1, j - 1].green && R[i, j].green > R[i - 1, j].green && R[i, j].green > R[i - 1, j + 1].green && R[i, j].green > R[i, j - 1].green && R[i, j].green > R[i, j + 1].green && R[i, j].green > R[i + 1, j - 1].green && R[i, j].green > R[i + 1, j].green && R[i, j].green > R[i + 1, j + 1].green) { Result[i, j].green = 1; count++; } if (R[i, j].blue > 0.1 * Rmax.blue && R[i, j].blue > R[i - 1, j - 1].blue && R[i, j].blue > R[i - 1, j].blue && R[i, j].blue > R[i - 1, j + 1].blue && R[i, j].blue > R[i, j - 1].blue && R[i, j].blue > R[i, j + 1].blue && R[i, j].blue > R[i + 1, j - 1].blue && R[i, j].blue > R[i + 1, j].blue && R[i, j].blue > R[i + 1, j + 1].blue) { Result[i, j].blue = 1; } } } return(Result); }
public static void GetMinMaxRGBValues(RGBPixel[,] ImageMatrix) { int Height = ImageOperations.GetHeight(ImageMatrix); int Width = ImageOperations.GetWidth(ImageMatrix); double Max = -100000000000, Min = 10000000000000; for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { double tmp = (double)ImageMatrix[j, i].red; if (tmp > Max) { Max = tmp; } if (tmp < Min) { Min = tmp; } } } minValue = Min; maxValue = Max; }