public static CifarItem ReadCifarImage(byte[] bb, long start) { var w = 32; var h = 32; Bitmap bmp = new Bitmap(32, 32); var label = bb[start]; CifarItem ret = new CifarItem(); ret.label = label; start++; NativeBitmap b = new NativeBitmap(bmp); for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { var _ind = (i * w + j); b.SetPixel(j, i, new byte[] { bb[start + _ind], bb[start + 1024 + _ind], bb[start + 2048 + _ind], 0xff }); } } ret.Bmp = b.GetBitmap(); var x = new InternalArray(new int[] { 1, 3, 32, 32 }); for (var dc = 0; dc < 3; dc++) { var i = 0; for (var xc = 0; xc < 32; xc++) { for (var yc = 0; yc < 32; yc++) { var px = ret.Bmp.GetPixel(xc, yc); var bt = (byte)((px.ToArgb() & (dc << 8)) >> 8); x.Set4D(0, dc, xc, yc, bt / 255.0f - 0.5f); i++; } } } ret.x = x; return(ret); }
public NativeBitmap GetBitmap() { if (_bitmap != null) { return(_bitmap); } Bitmap bmp = new Bitmap(Data.GetLength(0), Data.GetLength(1)); NativeBitmap rom = new NativeBitmap(bmp); for (int i = 0; i < Data.GetLength(0); i++) { for (int j = 0; j < Data.GetLength(1); j++) { rom.SetPixel(i, j, new[] { Data[i, j], Data[i, j], Data[i, j], (byte)255 }); } } _bitmap = rom; return(_bitmap); }