//将原始矩阵元素拆分为3份,分别为m0,m1,m2 public static void Decompose3(ImageCore img, out BmpGray8 r, out BmpGray8 g, out BmpGray8 b) { if (img.ElementSize % 3 != 0) { throw new Exception("Source Mat NOT 3 Channel"); } r = new BmpGray8(img.Width, img.Height); r.InitMemory(); g = new BmpGray8(img.Width, img.Height); g.InitMemory(); b = new BmpGray8(img.Width, img.Height); b.InitMemory(); T * src = (T *)img.Scan0.ToPointer(); T * p0 = (T *)r.Scan0.ToPointer(); T * p1 = (T *)g.Scan0.ToPointer(); T * p2 = (T *)b.Scan0.ToPointer(); int loopCount = r.Count; T * p = (T *)img.Scan0.ToPointer(); while (--loopCount > -1) { *p2++ = *p++; *p1++ = *p++; *p0++ = *p++; } }
public static void Threshold(ImageCore grayImage, out BmpGray8 region, byte min, byte max) { region = new BmpGray8(grayImage.Width, grayImage.Height); region.InitMemory(); int loopCount = grayImage.Count; byte *gp = (byte *)grayImage.Scan0.ToPointer(); byte *rp = (byte *)region.Scan0.ToPointer(); while (--loopCount > -1) { *rp++ = *gp >= min && *gp <= max?255:0; gp++; } }
// public static void Rgb3ToGray(BmpGray8 r, BmpGray8 g, BmpGray8 b, out BmpGray8 gray) { gray = new BmpGray8(r.Width, r.Height); gray.InitMemory(); byte *grayPtr = (byte *)gray.Scan0.ToPointer(); byte *rptr = (byte *)r.Scan0.ToPointer(); byte *gptr = (byte *)g.Scan0.ToPointer(); byte *bptr = (byte *)b.Scan0.ToPointer(); int loopCount = r.Count; while (--loopCount > -1) { #if GrayPrecision_16 *grayPtr++ = (byte)(((*rptr++) * 19595 + (*gptr++) * 38469 + (*bptr++) * 7472) >> 16); #elif GrayPrecision_8 *grayPtr++ = (byte)(((*rptr++) * 76 + (*gptr++) * 150 + (*bptr++) * 30) >> 8); #endif } }
public static unsafe BmpGray8 RLCListToImage(RLC_NodeList <byte> rlc, int width, int height) { BmpGray8 gray = new BmpGray8(width, height); gray.InitMemory(); IOperatorSet <byte> .Fill(gray, 0); RLC_Node <byte> node = rlc.head; int loopCount; byte * p = (byte *)gray.Scan0.ToPointer(); while (node != null) { loopCount = node.data.Length; while (--loopCount > -1) { *(p + node.data.Index + loopCount) = 0xff; } node = node.next; } return(gray); }