public override void PixelConverse(ref RGB[,] pixels, int height, int width) { RGB[,] pixelsX = new RGB[height, width]; Array.Copy(pixels, pixelsX, height * width); new SobelX().PixelConverse(ref pixelsX, height, width); new SobelY().PixelConverse(ref pixels, height, width); double mag; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { for (int p = 0; p < 3; p++) { mag = Math.Ceiling(Math.Sqrt(pixelsX[i, j].ArrayRGB[p] * pixelsX[i, j].ArrayRGB[p] + pixels[i, j].ArrayRGB[p] * pixels[i, j].ArrayRGB[p])); mag = Math.Abs(mag) > 255 ? 255 : Math.Abs(mag); pixelsX[i, j].ArrayRGB[p] = (byte)mag; } } } pixels = pixelsX; }
private byte Convolution(int i, int j, int width, int height, RGB[,] pixels, Kernel kernel, Parametr paramtr) { double sum = 0; for (int k = -kernel.R; k <= kernel.R; k++) { for (int l = -kernel.R; l <= kernel.R; l++) { int parametrValue = 0; switch (paramtr) { case Parametr.R: parametrValue = pixels[GetPixelIndex(i + k, width), GetPixelIndex(j + l, height)].Red; break; case Parametr.G: parametrValue = pixels[GetPixelIndex(i + k, width), GetPixelIndex(j + l, height)].Green; break; case Parametr.B: parametrValue = pixels[GetPixelIndex(i + k, width), GetPixelIndex(j + l, height)].Blue; break; } sum += kernel.Matrix[k + kernel.R, l + kernel.R] * parametrValue; } } return((byte)Math.Round(sum)); }
private static void SetValues16(Bitmap bitmap, RGB[,] mat) { BitmapData bitmapData = bitmap.LockBits(bitmap.Size.ToRect(), ImageLockMode.ReadWrite, bitmap.PixelFormat); try { unsafe { byte *ppixelRow = (byte *)bitmapData.Scan0; for (int y = 0; y < bitmap.Height; y++) { ushort *ppixelData = (ushort *)ppixelRow; for (int x = 0; x < bitmap.Width; x++) { // components are stored in BGR order, i.e. red component last //We have 3 numbers but must be merged in a single short //First 5 bits of blue, 6 bits of green and 5 bits of red //Then writes in the bitmap ppixelData[0] = mergeBits(mat[y, x].B, mat[y, x].G, mat[y, x].R); ppixelData += 1; } ppixelRow += bitmapData.Stride; } } } finally { bitmap.UnlockBits(bitmapData); } }
public RGB Multiplication_Matrice(int i, int j, int[,] Matrice_Convolution) { int Compteur = 0; int Red = 0; int Green = 0; int Blue = 0; RGB[,] Matrice_Pixel = { { Image[i - 1, j - 1], Image[i - 1, j], Image[i - 1, j + 1] }, { Image[i, j - 1], Image[i, j], Image[i, j + 1] }, { Image[i + 1, j - 1], Image[i + 1, j], Image[i + 1, j + 1] } }; for (int index1 = 0; index1 < Matrice_Convolution.GetLength(0); index1++) { for (int index2 = 0; index2 < Matrice_Convolution.GetLength(1); index2++) { Red += Matrice_Convolution[index1, index2] * Matrice_Pixel[index1, index2].Rouge; Green += Matrice_Convolution[index1, index2] * Matrice_Pixel[index1, index2].Vert; Blue += Matrice_Convolution[index1, index2] * Matrice_Pixel[index1, index2].Bleu; if (Matrice_Convolution[index1, index2] > 0) { Compteur++; } } } byte[] Pixel = { Convert.ToByte(Math.Abs(Red / Compteur)), Convert.ToByte(Math.Abs(Green / Compteur)), Convert.ToByte(Math.Abs(Blue / Compteur)) }; RGB New_RGB = new RGB(Pixel); return(New_RGB); }
public List <Centroid> RandomizeCentroids(RGB[,] pixels) { List <Centroid> centroids = new List <Centroid>(); while (centroids.Count < K) { Random random = new Random(); int x = random.Next(0, imageWidth); int y = random.Next(0, imageHeight); int R = pixels[x, y].R; int G = pixels[x, y].G; int B = pixels[x, y].B; bool flag = true; foreach (Centroid centroid in centroids) { if (centroid.R == R && centroid.G == G && centroid.B == B) { flag = false; } } if (flag) { centroids.Add(new Centroid(R, G, B, new List <RGB>())); } } return(centroids); }
private Vector[,,] MakeColorCube2(RGB[,] image) { Vector[,,] cube = new Vector[256, 256, 256]; for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { for (int k = 0; k < 256; k++) { cube[i, j, k] = new Vector(i, j, k, 0); //cube[i, j, k].X = i; //cube[i, j, k].Y = j; //cube[i, j, k].Z = k; } } } for (int x = 0; x < imageWidth; x++) { for (int y = 0; y < imageHeight; y++) { cube[image[x, y].R, image[x, y].G, image[x, y].B].Value++; } } return(cube); }
public void GaussianImage() { Task task = Task.Factory.StartNew(() => { ClearPerfomanceInfo(); RaisePropertyChanged("PerfomanceInfo"); CanNewExecute = false; try { GaussianFilter filter = new GaussianFilter(); RGB[,] pixels = ImageHelper.GetPixels(OriginImage.Bitmap); if (pixels != null) { filter.Filter(OriginImage.Bitmap.Width, OriginImage.Bitmap.Height, pixels, Sigma); SegmentedImage = new ImageViewModel(ImageHelper.GetFilterBitmap(pixels)); } } catch { } finally { CanNewExecute = true; } }); }
public void convertToImage(Image image, PixelFormat p, RGB[,] matrix) { using (Bitmap bitmap = (Bitmap)image) using (Bitmap bitmapCopy = new Bitmap(bitmap.Width, bitmap.Height, p)) { using (Graphics gr = Graphics.FromImage(bitmapCopy)) { gr.DrawImage(bitmap, bitmapCopy.Size.ToRect()); } Console.WriteLine($"Original PixelFormat: {bitmap.PixelFormat}"); // Format32bppArgb Console.WriteLine($"Copy PixelFormat: {bitmapCopy.PixelFormat}"); //Format48bppRgb if (p == PixelFormat.Format48bppRgb) { SetValues48(bitmapCopy, matrix); bitmapCopy.Save("../Images/Inverted16bpp.jpeg", ImageFormat.Jpeg); } else if (p == PixelFormat.Format24bppRgb) { SetValues24(bitmapCopy, matrix); bitmapCopy.Save("../Images/Inverted16bpp.jpeg", ImageFormat.Jpeg); } else { SetValues16(bitmapCopy, matrix); bitmapCopy.Save("../Images/Inverted16bpp.jpeg", ImageFormat.Jpeg); } } }
public static void version5(RGB[,] image, int max) { for (int i = 0; i < image.GetLength(0); i += 2) { for (int j = 0; j < image.GetLength(1); j += 2) { image[i, j].R = max - image[i, j].R; image[i + 1, j].R = max - image[i + 1, j].R; image[i, j + 1].R = max - image[i, j + 1].R; image[i + 1, j + 1].R = max - image[i + 1, j + 1].R; if (max == 31) { image[i, j].G = 63 - image[i, j].G; image[i + 1, j].G = 63 - image[i + 1, j].G; image[i, j + 1].G = 63 - image[i, j + 1].G; image[i + 1, j + 1].G = 63 - image[i + 1, j + 1].G; } else { image[i, j].G = max - image[i, j].G; image[i + 1, j].G = max - image[i + 1, j].G; image[i, j + 1].G = max - image[i, j + 1].G; image[i + 1, j + 1].G = max - image[i + 1, j + 1].G; } image[i, j].B = max - image[i, j].B; image[i + 1, j].B = max - image[i + 1, j].B; image[i, j + 1].B = max - image[i, j + 1].B; image[i + 1, j + 1].B = max - image[i + 1, j + 1].B; } } }
private Bitmap getBestMatchBitmap(RGB[,] i_PixelatedMatrix, List <TileBitmap> i_Bitmaps, int i_X, int i_Y) { RGB pixelRgb = i_PixelatedMatrix[i_X, i_Y]; List <RGB> bitMapsRgbs = new List <RGB>(i_Bitmaps.Count); foreach (TileBitmap bitmap in i_Bitmaps) { bitMapsRgbs.Add(bitmap.AvgColor); } int index = bitMapsRgbs.BinarySearch(pixelRgb); if (index < 0) { index = ~index; if (index == i_Bitmaps.Count) { index -= 1; } else if (index > 0) { if (i_Bitmaps[index].AvgColor.GetAverageColorDistance(pixelRgb) > i_Bitmaps[index - 1].AvgColor.GetAverageColorDistance(pixelRgb)) { index -= 1; } } } return(i_Bitmaps[index].Bitmap); }
public static void version2(RGB[,] image, int max) { for (int i = 0; i < image.GetLength(0); i++) { for (int j = 0; j < image.GetLength(1); j++) { image[i, j].R = max - image[i, j].R; } } for (int i = 0; i < image.GetLength(0); i++) { for (int j = 0; j < image.GetLength(1); j++) { if (max == 31) { image[i, j].G = 63 - image[i, j].G; } else { image[i, j].G = max - image[i, j].G; } } } for (int i = 0; i < image.GetLength(0); i++) { for (int j = 0; j < image.GetLength(1); j++) { image[i, j].B = max - image[i, j].B; } } }
private static void SetValues24(Bitmap bitmap, RGB[,] mat) { BitmapData bitmapData = bitmap.LockBits(bitmap.Size.ToRect(), ImageLockMode.ReadWrite, bitmap.PixelFormat); try { unsafe { byte *ppixelRow = (byte *)bitmapData.Scan0; for (int y = 0; y < bitmap.Height; y++) { byte *ppixelData = ppixelRow; //byte* ppixelData = ppixelRow; for (int x = 0; x < bitmap.Width; x++) { // components are stored in BGR order, i.e. red component last ppixelData[0] = (byte)mat[y, x].B; ppixelData[1] = (byte)mat[y, x].G; ppixelData[2] = (byte)mat[y, x].R; var i = ppixelData[0]; //int i = ppixelData[0]; ppixelData += 3; } ppixelRow += bitmapData.Stride; } } } finally { bitmap.UnlockBits(bitmapData); } }
public int[,] BuildSegments(int width, int height, RGB[,] pixels, int k, int minSize, ConnectingMethod connectingMethod, ColorDifference difType, ref PerfomanceInfo perfomanceInfo, int[,] superPixels) { var watch = Stopwatch.StartNew(); BuildGraph(width, height, pixels, connectingMethod, difType, superPixels); watch.Stop(); perfomanceInfo.BuildingPerfomance = watch.ElapsedMilliseconds; watch = Stopwatch.StartNew(); SortEdges(); watch.Stop(); perfomanceInfo.SortingPerfomance = watch.ElapsedMilliseconds; watch = Stopwatch.StartNew(); DoAlgorithm(k); watch.Stop(); perfomanceInfo.AlgorithmPerfomance = watch.ElapsedMilliseconds; watch = Stopwatch.StartNew(); if (minSize > 0) { MargeSmall(minSize); } watch.Stop(); perfomanceInfo.SmallSegmentMargingPerfomance = watch.ElapsedMilliseconds; return(ReindexSegments(width, height)); }
public RawBitmap(RGB[,] pixels) { int fileSize = 54 + 3 * pixels.GetLength(0) * pixels.GetLength(1); _datas = new byte[fileSize]; SetString(0, "BM"); SetInt(0x02, _datas.Length); SetInt(0x0A, 54); SetInt(0x0E, 40); // 54 = 0x0E + 40 SetInt(0x12, pixels.GetLength(1)); SetInt(0x16, pixels.GetLength(0)); SetShort(0x1A, 1); SetShort(0x1C, 24); for (int i = 0; i < pixels.GetLength(0); i++) // Height { for (int j = 0; j < pixels.GetLength(1); j++) // Width { int offset = 54 + 3 * (i * pixels.GetLength(1) + j); _datas[offset + 0] = pixels[pixels.GetLength(0) - 1 - i, j].B; _datas[offset + 1] = pixels[pixels.GetLength(0) - 1 - i, j].G; _datas[offset + 2] = pixels[pixels.GetLength(0) - 1 - i, j].R; } } }
public void LoadScreenShot(string fileName, string name) { _name = name; var image = Image.FromFile(fileName); var rawBitMap = new RawBitmap(image); _pixels = rawBitMap.ConvertDatas(); }
public void GenerateMosaicFromList(List <Bitmap> i_Bitmaps, int i_PixelSize) { RGB[,] pixelatedMatrix = createPixelatedImage(Image, i_PixelSize); List <TileBitmap> tileBitmaps = createTileBitmapsFromBitMaps(i_Bitmaps); tileBitmaps.Sort(); ImageMosaic = createMosaic(pixelatedMatrix, tileBitmaps, i_PixelSize); }
public void Get_Band_Gray_Gamma(RGB[,] Gamma, int band) { for (int gray = 0; gray < 8; gray++) { Gamma[band, gray].int_R = Convert.ToInt16(dataGridView_OC_param.Rows[band * 8 + (gray + 2)].Cells[1].Value.ToString()); Gamma[band, gray].int_G = Convert.ToInt16(dataGridView_OC_param.Rows[band * 8 + (gray + 2)].Cells[2].Value.ToString()); Gamma[band, gray].int_B = Convert.ToInt16(dataGridView_OC_param.Rows[band * 8 + (gray + 2)].Cells[3].Value.ToString()); Gamma[band, gray].String_Update_From_int(); } }
public RGB_Double Get_OC_Mode_RGB_Voltage(OC_Mode mode, int band, int gray) { if (band > DP213_Static.Max_HBM_and_Normal_Band_Amount) { throw new Exception("band should be less than " + DP213_Static.Max_HBM_and_Normal_Band_Amount); } RGB[,] OCMode_RGB = Get_OC_Mode_RGB(mode); return(Update_HBM_Normal_Gamma_Voltage(mode, band, gray, OCMode_RGB[band, gray])); }
public void AssignPixlesToCentroid(List <Centroid> centroids, RGB[,] image) { for (int x = 0; x < imageWidth; x++) { for (int y = 0; y < imageHeight; y++) { FindProperCentroid(centroids, image[x, y]); } } }
public void IterateThroughCentroids(List <Centroid> centroids, RGB[,] pixels) { int counter; do { counter = 0; AssignPixlesToCentroid(centroids, pixels); FindeNewCenterOfGravity(centroids, counter); }while (counter != 0); }
public void Set_OC_Mode_RGB(RGB Gamma, OC_Mode mode, int band, int gray) { dprotocal.api.WriteLine($"[Mode{mode}/Band{band}/grayindex{gray}] R[{Gamma.int_R}]/G[{Gamma.int_G}]/B[{Gamma.int_B}]", Color.Blue); RGB[,] OCMode_RGB = Get_OC_Mode_RGB(mode); OCMode_RGB[band, gray] = Gamma; if (band < DP213_Static.Max_HBM_and_Normal_Band_Amount) { Update_HBM_Normal_Gamma_Voltage(mode, band, gray, Gamma); } }
/// <summary> /// Creates a new Terrain. /// </summary> public Terrain(UInt32 version, Int16 gridMinX, Int16 gridMinZ, Int16 gridMaxX, Int16 gridMaxZ) { this.Version = version; if (version < 4) { CLUSTER_SIZE = 4; } if (version >= 4) { CLUSTER_SIZE = 16; } int width = gridMaxX - gridMinX; int height = gridMaxZ - gridMinZ; if (width % CLUSTER_SIZE != 0) { throw new ArgumentException($"Width must be a multiple of {CLUSTER_SIZE}.", "width"); } if (height % CLUSTER_SIZE != 0) { throw new ArgumentException($"Height must be a multiple of {CLUSTER_SIZE}.", "height"); } this.GridMinX = gridMinX; this.GridMinZ = gridMinZ; this.GridMaxX = gridMaxX; this.GridMaxZ = gridMaxZ; if (Version < 4) { this.HeightMap = new short[width, height]; } else { this.HeightMapFloat = new Single[width, height]; } this.ColorMap = new RGB[width, height]; this.NormalMap = new byte[width, height]; this.AlphaMap1 = new byte[width, height]; this.AlphaMap2 = new byte[width, height]; this.AlphaMap3 = new byte[width, height]; this.CellMap = new CellType[width, height]; this.InfoMap = new uint[width / CLUSTER_SIZE, height / CLUSTER_SIZE]; this.Clear(); this.heightMapMin = short.MaxValue; this.heightMapMax = short.MinValue; this.heightMapFloatMin = float.MaxValue; this.heightMapFloatMax = float.MinValue; }
public img(System.Drawing.Bitmap b) { Int32 x, y, width = b.Width, height = b.Height; RGB = new RGB[width, height]; for (x = 0; x < width; x++) { for (y = 0; y < height; y++) { RGB[x, y] = new RGB(b.GetPixel(x, y)); } } }
private DP213_OC_Offset() { AM1_Offset = new RGB[DP213_Static.Max_HBM_and_Normal_Band_Amount, DP213_Static.Max_Set_Amount]; Vreg1_Offset = new int[DP213_Static.Max_HBM_and_Normal_Band_Amount, DP213_Static.Max_Set_Amount]; RGB_Offset_From_OCMode1_to_OCMode2 = new RGB[DP213_Static.Max_HBM_and_Normal_Band_Amount, DP213_Static.Max_Gray_Amount]; RGB_Offset_From_OCMode1_to_OCMode3 = new RGB[DP213_Static.Max_HBM_and_Normal_Band_Amount, DP213_Static.Max_Gray_Amount]; string offset_file_path = Directory.GetCurrentDirectory() + "\\DP213\\Triple_Mode\\OC_Offset.csv"; Offset_Data = File.ReadLines(offset_file_path).Select(x => x.Split(',')).ToArray(); Update_Offset_Params(); }
public void PixelConverse(ref RGB[,] pixels, int height, int width) { byte gray; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { gray = (byte)(pixels[i, j].ArrayRGB[0] * 0.114 + pixels[i, j].ArrayRGB[1] * 0.587 + pixels[i, j].ArrayRGB[2] * 0.229); pixels[i, j].ArrayRGB[0] = pixels[i, j].ArrayRGB[1] = pixels[i, j].ArrayRGB[2] = gray; } } }
public void Set_All_Band_Set_AM1_By_Applying_Offset(RGB New_AM1) { RGB[,] AM1_Offset = DP213_OC_Offset.getInstance().getAM1Offset(); for (int band = 0; band < DP213_Static.Max_HBM_and_Normal_Band_Amount; band++) { Set_Band_Set_AM1(Gamma_Set.Set1, band, New_AM1 + AM1_Offset[band, 0]); Set_Band_Set_AM1(Gamma_Set.Set2, band, New_AM1 + AM1_Offset[band, 1]); Set_Band_Set_AM1(Gamma_Set.Set3, band, New_AM1 + AM1_Offset[band, 2]); Set_Band_Set_AM1(Gamma_Set.Set4, band, New_AM1 + AM1_Offset[band, 3]); Set_Band_Set_AM1(Gamma_Set.Set5, band, New_AM1 + AM1_Offset[band, 4]); Set_Band_Set_AM1(Gamma_Set.Set6, band, New_AM1 + AM1_Offset[band, 5]); } }
public img(Int32 width, Int32 height) { RGB = new RGB[width, height]; Int32 x, y; for (x = 0; x < width; x++) { for (y = 0; y < height; y++) { RGB[x, y] = new RGB(); } } }
public void DP116_Get_All_Band_Gray_Gamma(RGB[,] Gamma) { for (int band = 0; band < 12; band++) { for (int gray = 0; gray < 10; gray++) { Gamma[band, gray].int_R = Convert.ToInt16(dataGridView_OC_param.Rows[band * 10 + (gray + 2)].Cells[1].Value.ToString()); Gamma[band, gray].int_G = Convert.ToInt16(dataGridView_OC_param.Rows[band * 10 + (gray + 2)].Cells[2].Value.ToString()); Gamma[band, gray].int_B = Convert.ToInt16(dataGridView_OC_param.Rows[band * 10 + (gray + 2)].Cells[3].Value.ToString()); Gamma[band, gray].String_Update_From_int(); } } }
private static void FillFilterPixels(RGB[,] filter, byte[] pixels, int width, int height, int stride) { Random random = new Random(); Dictionary <int, byte[]> colors = new Dictionary <int, byte[]>(); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { int idx = j * stride + i * 3; pixels[idx] = filter[i, j].Blue; pixels[idx + 1] = filter[i, j].Green; pixels[idx + 2] = filter[i, j].Red; } } }
public static Bitmap RGBToImage(RGB[,] image) { int width = image.GetLength(0); int height = image.GetLength(1); Bitmap result = new Bitmap(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { result.SetPixel(x, y, Color.FromArgb(image[x, y].R, image[x, y].G, image[x, y].B)); } } return(result); }
/// <summary> /// Creates a new Terrain. /// </summary> public Terrain(int width, int height) { if (width % 4 != 0) throw new ArgumentException("Width must be a multiple of 4.", "width"); if (height % 4 != 0) throw new ArgumentException("Height must be a multiple of 4.", "height"); this.Width = width; this.Height = height; this.HeightMap = new short[width, height]; this.ColorMap = new RGB[width, height]; this.NormalMap = new byte[width, height]; this.AlphaMap1 = new byte[width, height]; this.AlphaMap2 = new byte[width, height]; this.AlphaMap3 = new byte[width, height]; this.CellMap = new CellType[width, height]; this.InfoMap = new uint[width / 4, height / 4]; this.Clear(); this.heightMapMin = short.MaxValue; this.heightMapMax = short.MinValue; }