private void AddRectanglePixelsInmatrix(ImagePixel[,] pixels, ImageRectangle rectangle, int xRectanglePosition, int yRectanglePosition) { ImagePixel[,] rectanglePixels = rectangle.PixelsMatrix; for (int m = 0, i = xRectanglePosition * rectangle.M; m < rectangle.M; m++, i++) { for (int n = 0, j = yRectanglePosition * rectangle.N; n < rectangle.N; n++, j++) { pixels[i, j] = rectanglePixels[m, n]; } } }
private Image AssembleImageFromPixels(ImagePixel[,] pixels, int height, int width) { Bitmap bitmap = new Bitmap(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { ImagePixel pixel = pixels[i, j]; if (pixel == null) { pixel = new ImagePixel(0, 0, 0); } Color color = Color.FromArgb((Int32)pixel.R, (Int32)pixel.G, (Int32)pixel.B); bitmap.SetPixel(i, j, color); } } return bitmap as Image; }
private ImagePixel[,] GetConvertedPixels(Color[,] pixels) { ImagePixel[,] pixelsMatrix = new ImagePixel[m, n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { pixelsMatrix[i, j] = GetConvertedPixel(pixels, i, j); } } return pixelsMatrix; }
private ImagePixel GetConvertedPixel(Color[,] pixels, int i, int j) { double r = pixels[i, j].R; double g = pixels[i, j].G; double b = pixels[i, j].B; ImagePixel pixel = new ImagePixel(Convert(r), Convert(g), Convert(b)); return pixel; }
private void ConvertPixelsInStandardForm(ImagePixel[,] pixels, int height, int width) { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { ConvertPixelInStandardForm(pixels[i, j]); } } }
private void ConvertPixelInStandardForm(ImagePixel pixel) { if (pixel == null) { pixel = new ImagePixel(0, 0, 0); return; } pixel.R = ConvertToStandardForm(pixel.R); pixel.G = ConvertToStandardForm(pixel.G); pixel.B = ConvertToStandardForm(pixel.B); }
private ImagePixel[,] AssembleRectanglesToPixelMatrix(ImageRectangle[] pixelsRectangels, int height, int width) { ImagePixel[,] pixels = new ImagePixel[width, height]; int xRectanglePosition = 0; int yRectanglePosition = 0; for (int p = 0; p < pixelsRectangels.Length; p++) { ImageRectangle rectangle = pixelsRectangels[p]; AddRectanglePixelsInmatrix(pixels, rectangle, xRectanglePosition, yRectanglePosition); if (xRectanglePosition >= (width / rectangle.M) - 1) { xRectanglePosition = 0; yRectanglePosition++; } else { xRectanglePosition++; } } return pixels; }