static int GetDiff(System.Drawing.Bitmap origin, System.Drawing.Bitmap target) { int sum = 0; for (int y = 0; y < Math.Max(origin.Height, target.Height); y++) { for (int x = 0; x < Math.Max(origin.Width, target.Width); x++) { System.Drawing.Color co = new System.Drawing.Color(); System.Drawing.Color ct = new System.Drawing.Color(); if ( origin.Width > x && origin.Height > y) { co = origin.GetPixel(x, y); } if (target.Width > x && target.Height > y) { ct = target.GetPixel(x, y); } sum += (Math.Abs(co.R - ct.R) + Math.Abs(co.G - ct.G) + Math.Abs(co.B - ct.B) + Math.Abs(co.A - ct.A)); } } return sum; }
private System.Drawing.Bitmap DrawCharacter(System.Drawing.Bitmap bmp, System.Drawing.Color color, int size) { for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { System.Drawing.Color pixel = bmp.GetPixel(x, y); if (pixel != System.Drawing.Color.FromArgb(0, 0, 0, 0)) { if (pixel == System.Drawing.Color.FromArgb(255, 249, 249, 249)) bmp.SetPixel(x, y, System.Drawing.Color.White); else { int red = (pixel.R + color.R) / 2; int green = (pixel.G + color.G) / 2; int blue = (pixel.B + color.B) / 2; bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(red, green, blue)); } } } } System.Drawing.Bitmap newImage = new System.Drawing.Bitmap(size, size); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newImage)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, size, size)); } return newImage; }
public static byte[] GetHeightMap(System.Drawing.Bitmap bm) { byte[] result = new byte[bm.Height * bm.Width]; for (int x = 0; x < bm.Width; x++) { for (int y = 0; y < bm.Height; y++) { result[x + y * bm.Width] = bm.GetPixel(x, y).R; } } return result; }
/// <summary> /// Convets Bitmaps to color Sifteo.Color array. /// </summary> /// <returns> /// The to color array. /// </returns> /// <param name='bitmap'> /// Bitmap. /// </param> public Sifteo.Color[,] bitmapToColorArray (System.Drawing.Bitmap bitmap) { Sifteo.Color[,] colors = new Sifteo.Color[bitmap.Width,bitmap.Height]; for (int i =0; i < bitmap.Width; i++) { for (int j=0; j < bitmap.Height; j++) { System.Drawing.Color c = bitmap.GetPixel (i, j); colors [i,j] = new Sifteo.Color (c.R, c.G, c.B); } } return colors; }
public static List<LED_Set> ConvertImageToLEDArray(int Light_Count, System.Drawing.Bitmap BitmapImage) { List<LED_Set> loaded_animation = new List<LED_Set> (); loaded_animation.Clear (); System.Drawing.Color CurrentColor; for (int y = 0; y < BitmapImage.Height; y++) { loaded_animation.Add (new LED_Set ()); for (int x = 0; x < Light_Count; x++) { CurrentColor = BitmapImage.GetPixel (x, y); loaded_animation [y].LED_Values.Add (new LED (CurrentColor.R, CurrentColor.G, CurrentColor.B)); } } return loaded_animation; }
/// <summary> /// 周囲の黒い部分を除いた部分の範囲を返す /// </summary> /// <param name="bitmap">処理対象の画像</param> /// <returns>中央のマップ部分の範囲</returns> private static System.Drawing.Rectangle measureTrimmingRect(System.Drawing.Bitmap bitmap) { Contract.Requires<ArgumentNullException>(bitmap != null); var result = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height); var trimColor = System.Drawing.Color.Black; int centerX = bitmap.Width / 2, centerY = bitmap.Height / 2; if (compareSimilarColor(trimColor, bitmap.GetPixel(centerX, centerY))) { return result; } while (++result.X < bitmap.Width) { if (!compareSimilarColor(trimColor, bitmap.GetPixel(result.X, centerY))) { break; } } while (++result.Y < bitmap.Height) { if (!compareSimilarColor(trimColor, bitmap.GetPixel(centerX, result.Y))) { break; } } for (int right = bitmap.Width-1; right > result.X; --right) { if (!compareSimilarColor(trimColor, bitmap.GetPixel(right, centerY))) { result.Width = right + 1 - result.X; break; } } for (int bottom = bitmap.Height-1; bottom > result.Y; --bottom) { if (!compareSimilarColor(trimColor, bitmap.GetPixel(centerX, bottom))) { result.Height = bottom + 1 - result.Y; break; } } return result; }
public static Image CreateFromBitmap(System.Drawing.Bitmap bm) { Image imm = new Image(); imm.HRes = bm.Width; imm.VRes = bm.Height; imm.Pixels = new Vector3[imm.VRes * imm.HRes]; for (int x = 0; x < imm.HRes; x++) { for (int y = 0; y < imm.VRes; y++) { var c = bm.GetPixel(x, y); imm.Pixels[x + y * imm.HRes] = new Vector3((((float)c.R) / 255.0f), (((float)c.G) / 255.0f), (((float)c.B) / 255.0f)); } } return imm; }
public static System.Drawing.Color[][] BitMapToColors(System.Drawing.Bitmap pic) { // System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(pic.Length.Length, pic[0].Length); System.Drawing.Color[][] ret; ret = new System.Drawing.Color[pic.Width][]; for (int w = 0; w < pic.Width; w++) { ret[w]= new System.Drawing.Color[pic.Height]; for (int h = 0; h < pic.Height; h++) ret[w][h] = pic.GetPixel(w, h); } return ret; }
public static System.Drawing.Color[,] BitMapToColorsArray(System.Drawing.Bitmap pic) { System.Drawing.Color[,] ret; ret = new System.Drawing.Color[pic.Height, pic.Width]; for (int w = 0; w < pic.Width; w++) { // ret[w] = new System.Drawing.Color[pic.Height]; for (int h = 0; h < pic.Height; h++) ret[h,w] = pic.GetPixel(w, h); } return ret; }
public System.Drawing.Bitmap BitmapToBlackWhite2(System.Drawing.Bitmap src) { double treshold = 0.6; Bitmap dst = new Bitmap(src.Width, src.Height); for (int i = 0; i < src.Width; i++) { for (int j = 0; j < src.Height; j++) { dst.SetPixel(i, j, src.GetPixel(i, j).GetBrightness() < treshold ? System.Drawing.Color.Black : System.Drawing.Color.White); } } return dst; }
public static Bitmap LoadBitmap(System.Drawing.Bitmap bmp) { int w = bmp.Width; int h = bmp.Height; Bitmap result = new Bitmap(w, h); for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { System.Drawing.Color pixel = bmp.GetPixel(x, y); int argb = pixel.ToArgb(); int col = (argb & 0xf) >> 2; if (pixel.A == 255 && pixel.R == 255 && pixel.G == 0 && pixel.B == 255) col = -1; result.pixels[x + y * w] = col; } } return result; }
ImageSurface BitmapToSurface(System.Drawing.Bitmap bmp) { Int32[] data = new Int32[bmp.Width * bmp.Height]; for (int y = 0; y < bmp.Height; y++) for (int x = 0; x < bmp.Width; x++) { System.Drawing.Color col = bmp.GetPixel(x, y); data[x + y * bmp.Width] = col.ToArgb(); } // pin databuffer until imgSurf is destroyed _gc_h_surface_data_buffer = System.Runtime.InteropServices.GCHandle.Alloc(data, System.Runtime.InteropServices.GCHandleType.Pinned); // create image surface IntPtr dataPtr = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(data, 0); ImageSurface imgSurf = new ImageSurface(dataPtr, Format.Argb32, bmp.Width, bmp.Height, bmp.Width * 32 / 8); return imgSurf; }
public long[] GetHistogram(System.Drawing.Bitmap picture) { long[] myHistogram = new long[256]; for (int i = 0; i < picture.Size.Width; i++) for (int j = 0; j < picture.Size.Height; j++) { System.Drawing.Color c = picture.GetPixel(i, j); long Temp = 0; Temp += c.R; Temp += c.G; Temp += c.B; Temp = (int)Temp / 3; myHistogram[Temp]++; } return myHistogram; }
public static IntPtr CreateMaskFromImage(Display display, System.Drawing.Bitmap image) { int width = image.Width; int height = image.Height; int stride = (width + 7) >> 3; byte[] mask = new byte[stride * height]; bool msbfirst = (XBitmapBitOrder(display) == 1); // 1 = MSBFirst for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { byte bit = (byte) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); int offset = y * stride + (x >> 3); if (image.GetPixel(x, y).A >= 128) mask[offset] |= bit; } } return XCreatePixmapFromBitmapData(display, XDefaultRootWindow(display), mask, width, height, new IntPtr(1), IntPtr.Zero, 1); }
//public Image(int width, int height) //{ // _pixels = new Pixel[width, height]; // for (int x = 0; x < width; x++) // for (int y = 0; y < height; y++) // _pixels[x, y] = new Pixel(x, y); //} public Image(double width, double height, System.Drawing.Bitmap bitmap, Interpolators.IInterpolator interpolator) { if (interpolator == null) throw new ArgumentNullException("interpolator", "interpolator is null."); if (bitmap == null) throw new ArgumentNullException("bitmap", "bitmap is null."); if (Width < 0) throw new Exception("Width can't be negative"); if (Height < 0) throw new Exception("Height can't be negative"); Width = width; Height = height; _interpolator = interpolator; ScaleHorizontal = (bitmap.Width - 1) / Width; ScaleVertical = (bitmap.Height - 1) / Height; _pixels = new Pixel[bitmap.Width, bitmap.Height]; for (int x = 0; x < bitmap.Width; x++) for (int y = 0; y < bitmap.Height; y++) _pixels[x, y] = new Pixel(bitmap.GetPixel(x, bitmap.Height - y - 1).GetBrightness(), x, y); }
/// <summary> /// Method to generate the analysis data. /// </summary> public AnalysisInfo analyse(System.Drawing.Bitmap frameRef, System.Drawing.Bitmap frameProc) { AnalysisInfo analyse = null; if (frameRef != null && frameProc != null) { Bitmap resultFrame = new Bitmap(frameRef.Width, frameRef.Height); double sum = 0; double sumR = 0; double sumG = 0; double sumB = 0; //int rb = (propertiesView.getRb()); float[] resultValues = new float[4]; for (int i = 0; i < frameRef.Height - 1; i++) { for (int j = 0; j < frameRef.Width - 1; j++) { int newPixel = 0; //Get Color from Proc Color colorProc = frameProc.GetPixel(j, i); int alphaProc = colorProc.A; int redProc = colorProc.R; int greenProc = colorProc.G; int blueProc = colorProc.B; //Get Color from Ref Color colorRef = frameRef.GetPixel(j, i); int alphaRef = colorRef.A; int rotRef = colorRef.R; int grunRef = colorRef.G; int blauRef = colorRef.B; //RGB int newRed = (int)Math.Pow((redProc - rotRef), 2); int newGreen = (int)Math.Pow((greenProc - grunRef), 2); int newBlue = (int)Math.Pow((blueProc - blauRef), 2); sum += newBlue / 3 + newGreen / 3 + newRed / 3; sumR += newRed; sumG += newGreen; sumB += newBlue; switch (radioButton) { case 0: newPixel = (((alphaProc + alphaRef) / 2) << 24) | (newRed << 16) | (newGreen << 8) | newBlue; break; case 1: newPixel = (((alphaProc + alphaRef) / 2) << 24) | (newRed << 16) | (0 << 8) | 0; break; case 2: newPixel = (((alphaProc + alphaRef) / 2) << 24) | (0 << 16) | (newGreen << 8) | 0; break; case 3: newPixel = (((alphaProc + alphaRef) / 2) << 24) | (0 << 16) | (0 << 8) | newBlue; break; } resultFrame.SetPixel(j, i, Color.FromArgb(newPixel)); } } resultValues[0] = (float)sum / (frameProc.Height * frameProc.Width); resultValues[1] = (float)sumR / (frameProc.Height * frameProc.Width); resultValues[2] = (float)sumG / (frameProc.Height * frameProc.Width); resultValues[3] = (float)sumB / (frameProc.Height * frameProc.Width); analyse = new AnalysisInfo(resultFrame, resultValues); } return analyse; }
/// <summary> /// 红色滤镜 /// </summary> /// <param name="bitmap">Bitmap</param> /// <param name="threshold">阀值 -255~255</param> /// <returns></returns> public System.Drawing.Bitmap AdjustToRed(System.Drawing.Bitmap bitmap, int threshold) { for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { // 取得每一個 pixel var pixel = bitmap.GetPixel(x, y); var pR = pixel.R + threshold; pR = Math.Max(pR, 0); pR = Math.Min(255, pR); // 將改過的 RGB 寫回 // 只寫入紅色的值 , G B 都放零 System.Drawing.Color newColor = System.Drawing.Color.FromArgb(pixel.A, pR, 0, 0); bitmap.SetPixel(x, y, newColor); } } // 回傳結果 return bitmap; }
/// <summary> /// 绿色滤镜 /// </summary> /// <param name="bitmap">一个图片实例</param> /// <param name="threshold">阀值 -255~+255</param> /// <returns></returns> public System.Drawing.Bitmap AdjustToGreen(System.Drawing.Bitmap bitmap, int threshold) { for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { // 取得每一個 pixel var pixel = bitmap.GetPixel(x, y); //判斷是否超過255 如果超過就是255 var pG = pixel.G + threshold; //如果小於0就為0 if (pG > 255) pG = 255; if (pG < 0) pG = 0; // 將改過的 RGB 寫回 // 只寫入綠色的值 , R B 都放零 System.Drawing.Color newColor = System.Drawing.Color.FromArgb(pixel.A, 0, pG, 0); bitmap.SetPixel(x, y, newColor); } } // 回傳結果 return bitmap; }
/// <summary> /// 调整 RGB 色调 /// </summary> /// <param name="bitmap"></param> /// <param name="thresholdRed">红色阀值</param> /// <param name="thresholdBlue">蓝色阀值</param> /// <param name="thresholdGreen">绿色阀值</param> /// <returns></returns> public System.Drawing.Bitmap AdjustToCustomColor(System.Drawing.Bitmap bitmap, int thresholdRed, int thresholdGreen, int thresholdBlue) { for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { // 取得每一個 pixel var pixel = bitmap.GetPixel(x, y); //判斷是否超過255 如果超過就是255 var pG = pixel.G + thresholdGreen; //如果小於0就為0 if (pG > 255) pG = 255; if (pG < 0) pG = 0; //判斷是否超過255 如果超過就是255 var pR = pixel.R + thresholdRed; //如果小於0就為0 if (pR > 255) pR = 255; if (pR < 0) pR = 0; //判斷是否超過255 如果超過就是255 var pB = pixel.B + thresholdBlue; //如果小於0就為0 if (pB > 255) pB = 255; if (pB < 0) pB = 0; // 將改過的 RGB 寫回 // 只寫入綠色的值 , R B 都放零 System.Drawing.Color newColor = System.Drawing.Color.FromArgb(pixel.A, pR, pG, pB); bitmap.SetPixel(x, y, newColor); } } return bitmap; }
private void ChangeAnnounceColor(System.Drawing.Bitmap image) { var pixel = image.GetPixel(1, 1); var brightness = pixel.GetBrightness(); if (brightness > 0.5) { txtAnuncio.Foreground = Brushes.Black; } else { txtAnuncio.Foreground = Brushes.White; } firstFrame = true; }
public static int GetImageAVGRgb(System.Drawing.Bitmap _im) { int _w = _im.Width - 1; int _h = _im.Height - 1; int r = 0, g = 0, b = 0; for (int w = 1; w < _w; w++) { for (int h = 1; h < _h; h++) { Color c = _im.GetPixel(w, h); r += c.R; g += c.G; b += c.B; } } r = r / (_w * _w); g = g / (_w * _w); b = b / (_w * _w); string hex = Color.FromArgb(r, g, b).Name.Substring(2); int sayi = HexToInt(hex); return sayi; }
private void DUMP_TEX_PIXELS(System.Drawing.Bitmap bitmap) { for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { Console.Write ("{0:X} ", bitmap.GetPixel (i, j).ToArgb ()); } Console.WriteLine ("-"); } }
private static void CopyBitmapToBitmap( System.Drawing.Bitmap source, System.Drawing.Bitmap destination, System.Drawing.Point destPoint ) { int count = source.Width * source.Height; int width = source.Width; int destX = destPoint.X; int destY = destPoint.Y; for ( int i = 0; i < count; i++ ) { destination.SetPixel( destX + i % width, destY + i / width, source.GetPixel( i % width, i / width ) ); } }
public override void paint(System.Drawing.Bitmap b) { boundaryfill4(position.X,position.Y,FillColor,b.GetPixel(position.X,position.Y),b); }
/// <summary> /// Loads the bitmap by cloning its data to a more compatible format. /// </summary> /// <param name="bitmap"> /// A <see cref="Drawing.Bitmap"/> to be converted into an <see cref="Image"/> instance. /// </param> /// <param name='image'> /// A <see cref="Image"/> instance that will store <paramref name="bitmap"/> data. /// </param> /// <exception cref="ArgumentNullException"> /// Exception thrown if <paramref name="bitmap"/> or <paramref name="image"/> is null. /// </exception> /// <remarks> /// <para> /// Cloning <paramref name="bitmap"/> is useful whenever the bitmap have a pixel format not directly portable /// to any well-known format (i.e. 1 bit pixel, palettized pixel, etc.). /// </para> /// <para> /// This method is very memory consuming, because cloning cause to use additionally memory. /// </para> /// </remarks> private static void LoadBitmapByPixel(System.Drawing.Bitmap bitmap, Image image) { if (bitmap == null) throw new ArgumentNullException("bitmap"); if (image == null) throw new ArgumentNullException("image"); // FIXME Maybe this method is no more necessary throw new NotImplementedException(); #if false for (uint y = 0; y < image.Height; y++) { for (uint x = 0; x < image.Width; x++) { System.Drawing.Color bitmapColor = bitmap.GetPixel((int)x, (int)y); //image[x, y] = Pixel.GetNativeIColor(new ColorRGBA32(bitmapColor.R, bitmapColor.G, bitmapColor.B, bitmapColor.A), image.PixelLayout); //image[x, y] = new ColorBGR24(bitmapColor.R, bitmapColor.G, bitmapColor.B); } } #endif }
public void Cal(System.Drawing.Bitmap colorBitmap, ushort[] depthPixels, CameraSpacePoint[] ColorInSkel, ushort[] depth4background, int[] boolpixel) { int ColorCenterXsum = 0, ColorCenterYsum = 0, uuSum = 0, vvSum = 0, Cnt = 0; List<double> Xsum = new List<double>(); List<double> Ysum = new List<double>(); List<double> Zsum = new List<double>(); for (int i = (int)ColorCenter.X - SearchRange; i < ColorCenter.X + SearchRange; i++) { for (int j = (int)ColorCenter.Y - SearchRange; j < ColorCenter.Y + SearchRange; j++) { if (i <= 0 || i >= 511 || j <= 0 || j >= 423) break; //avoid edge prob. int di = (i + j * 512); //di = depthpixel index //int ci = di * 4; //ci = colorPixel index //nt ci = (int)(4 * ((i * 424 * 2.547) + (j * 512 * 3.75))); //ci = colorPixel index UU = -0.169 * colorBitmap.GetPixel(i, j).R - 0.331 * colorBitmap.GetPixel(i, j).G + 0.5 * colorBitmap.GetPixel(i, j).B + 128; VV = 0.5 * colorBitmap.GetPixel(i, j).R - 0.419 * colorBitmap.GetPixel(i, j).G - 0.081 * colorBitmap.GetPixel(i, j).B + 128; //UU = -0.169 * colorPixels[ci + 2] - 0.331 * colorPixels[ci + 1] + 0.5 * colorPixels[ci] + 128; //VV = 0.5 * colorPixels[ci + 2] - 0.419 * colorPixels[ci + 1] - 0.081 * colorPixels[ci] + 128; if (UU > AverageUU - uvRange && UU < AverageUU + uvRange && VV > AverageVV - uvRange && VV < AverageVV + uvRange && UU > CenterUU - CenterUVrange && UU < CenterUU + CenterUVrange && VV > CenterVV - CenterUVrange && VV < CenterVV + CenterUVrange && (boolpixel[di] == 0 || boolpixel[di] == TargetID)) //&& Math.Abs(depthPixels[di].Depth - depth4background[di].Depth) > DepthRange //深度背景相減 //&& (ColorInSkel[di].Z != 0 && ColorInSkel[di].Z < 2.5 )) //這裡先不管Z值部分,所以先不做 { boolpixel[di] = TargetID; uuSum += (int)UU; vvSum += (int)VV; colorBitmap.SetPixel(i, j, System.Drawing.Color.FromArgb(0, 0, 0, 0)); // (byte)depthPixels[depthIndex].Depth; ColorCenterXsum += i; ColorCenterYsum += j; Cnt++; //顏色追蹤歸顏色追蹤,Z值追蹤歸Z值追蹤 ;即使zCnt值不夠,UV值、中心點仍繼續更新 //int offsetindex = (i * 512 / 1920) + (j * 424 / 1080 * 512); if (ColorInSkel[di].Z != 0 && ColorInSkel[di].Z < TheDeepestDetectDistance) //2.5 // 必須要先轉,因為在後面做平均之後值會跑掉(雖然理論上不會阿QAQ) { //Xsum.Add(ColorInSkel[offsetindex].X); //Ysum.Add(ColorInSkel[offsetindex].Y); //Zsum.Add(ColorInSkel[offsetindex].Z); XYZ.X = ColorInSkel[di].X; XYZ.Y = ColorInSkel[di].Y; XYZ.Z = ColorInSkel[di].Z; Console.WriteLine(ColorInSkel[di].X.ToString() + "," + ColorInSkel[di].Y.ToString() + "," + ColorInSkel[di].Z.ToString()); AverageUU = UU; AverageVV = VV; ColorCenter.X = ColorCenterXsum / Cnt; ColorCenter.Y = ColorCenterYsum / Cnt; TrackState = true; //Cnt++; } else { SearchRange = 10; // TrackState = false; } } else boolpixel[di] = 0; } } //if (Cnt > 2) //{ // AverageUU = uuSum / Cnt; // AverageVV = vvSum / Cnt; // ColorCenter.X = ColorCenterXsum / Cnt; // ColorCenter.Y = ColorCenterYsum / Cnt; // if (Zsum.Count > 3) // { // XYZ.X = Xsum.Average(); // XYZ.Y = Ysum.Average(); // XYZ.Z = Zsum.Average(); // } // //height = XYZ.Z* Math.Sin((Math.PI / 180) * ((240 - ColorCenter.Y) / 240 * 27)) + KinectHeight; // 21.5=>27 // SearchRange = 5; // TrackState = true; //} //else //{ // TrackState = false; // SearchRange = 10; //} ColorCenterXsum = 0; ColorCenterYsum = 0; Cnt = 0; uuSum = 0; vvSum = 0; }
public CCFTree BuildCCFTree(System.Drawing.Bitmap original) { CCFTree Tree = CCFTree.MakeInitialTree(L,B,0); int i,j; CCFTree Leaf; CCFTree newChild; Color entry; Color pixel; Color merged; long distance; long minColDis = 0; for(i=0;i<original.Width;i++) { for(j=0;j<original.Height;j++) { pixel = original.GetPixel(i,j); // find the closest entry in leaf node and calulate the distance Tree.FindClosestLeafAndEntry(pixel, out Leaf, out entry); if (!entry.Equals(pixel)) // si no esta ese mismo color en el arbol { distance = CalculateDistance(pixel, entry); if (distance < Tree.T) { //merge the new color with the entry merged = Leaf.Merge(entry,pixel); } else { //record the minimal color distance minColDis that is larger than T if (minColDis==0) {minColDis = distance;} else {minColDis = Math.Min(distance,minColDis);} if (Leaf.CountEntries < L) { // if the child number of leaf node smaller than L, // add the new color into leaf node as a new entry. Leaf.AddEntry(pixel); } else { // generate a new leaf node newChild and add the new color to newChild newChild = CCFTree.MakeEmptyLeaf(L, B, Tree.T); newChild.AddEntry(pixel); if (Leaf.Father.CountChildren < B) { // add the newChild to father Leaf.Father.AddChild(newChild); } else { // call split_father(father,newChild); Leaf.Father.SplitFather(newChild); } } } // if the number of all entries in leaf nodes larger than N, // :? N = 2K // :? k denotes NumColors if (Tree.CountEntriesInLeafs>2*NumColors) { // let T be minColDis and call rebuild(); Tree.T = (int)minColDis; minColDis = 0; Tree = Tree.Rebuild(); } } // fin si ya existe en el arbol } } return Tree; }
public void GenFromFile(System.Drawing.Bitmap img) { Source = TileGridSource.FILE; if(img.Width != Width || img.Height != Height){ GenEmptyGrid(); return; } for (int x = 0; x < Width; x++){ for (int y = 0; y < Height; y++){ System.Drawing.Color pixel = img.GetPixel(x, y); if (pixel.R == 0 && pixel.G == 0 && pixel.B == 0){ //#000000 - Black Grid[x, y] = new Tile(TileType.CLOSED); } else if(pixel.R == 255 && pixel.G == 255 && pixel.B == 255) { //#FFFFFF - White Grid[x, y] = new Tile(TileType.OPEN); } else if(pixel.R == 255 && pixel.G == 0 && pixel.B == 0) { //#FF0000 - Red Grid[x, y] = new Tile(TileType.END); } else if(pixel.R == 0 && pixel.G == 255 && pixel.B == 0) { //#00FF00 - Green Grid[x, y] = new Tile(TileType.START); } else { Grid[x, y] = new Tile(TileType.OPEN); } } } if(!IsValidGrid()){ GenEmptyGrid(); } }
/// <summary> /// Method to generate the analysis data. /// </summary> public AnalysisInfo analyse(System.Drawing.Bitmap frameRef, System.Drawing.Bitmap frameProc) { Bitmap resultFrame = new Bitmap(frameRef.Width, frameRef.Height); double summe = 0; float[] resultValues = new float[1]; for (int i = 0; i < frameRef.Height - 1; i++) { for (int j = 0; j < frameRef.Width - 1; j++) { int newPixel = 0; Color colorProc = frameProc.GetPixel(j, i); int alphaProc = colorProc.A; int rotProc = colorProc.R; int grunProc = colorProc.G; int blauProc = colorProc.B; Color colorRef = frameRef.GetPixel(j, i); int alphaRef = colorRef.A; int rotRef = colorRef.R; int grunRef = colorRef.G; int blauRef = colorRef.B; //RGB int newRot = (int)Math.Pow((rotProc - rotRef), 2); int newGrun = (int)Math.Pow((grunProc - grunRef), 2); int newBlau = (int)Math.Pow((blauProc - blauRef), 2); summe = summe + newBlau + newGrun + newRot ; newPixel = (((alphaProc + alphaRef) / 2) << 24) | (newRot << 16) | (newGrun << 8) | newBlau; resultFrame.SetPixel(j, i, Color.FromArgb(newPixel)); } } float mse = (float)summe / (frameProc.Height * frameProc.Width*3); if(0<=mse&&mse<=1) { resultValues[0] = -1; } else { resultValues[0] = (float)(20*Math.Log10(255)-10*Math.Log10(mse)); } AnalysisInfo analyse = new AnalysisInfo(resultFrame, resultValues); return analyse; }
private bool MatchesComparisonPixel(ComparisonPixel basePixel, System.Drawing.Bitmap casinoScreenshot, System.Drawing.Bitmap originalCasinoScreenshot) { //TODO use color difference algorithm var dPosition = basePixel.Position.ToDrawingPoint(); var pixelColor = casinoScreenshot.GetPixel(dPosition.X, dPosition.Y); return basePixel.Color.Equals(pixelColor); }