private WriteableBitmap GenerateBitmap(Image3d t_img, uint[] t_map) { Debug.Assert(t_img.format == ImageFormat.FORMAT_U8); WriteableBitmap bitmap = new WriteableBitmap(t_img.dims[0], t_img.dims[1], 96.0, 96.0, PixelFormats.Rgb24, null); bitmap.Lock(); unsafe { for (int y = 0; y < bitmap.Height; ++y) { for (int x = 0; x < bitmap.Width; ++x) { byte t_val = t_img.data[x + y * t_img.stride0]; // lookup tissue color byte[] channels = BitConverter.GetBytes(t_map[t_val]); // assign red, green & blue byte *pixel = (byte *)bitmap.BackBuffer + x * (bitmap.Format.BitsPerPixel / 8) + y * bitmap.BackBufferStride; pixel[0] = channels[0]; // red pixel[1] = channels[1]; // green pixel[2] = channels[2]; // blue // discard alpha channel } } } bitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight)); bitmap.Unlock(); return(bitmap); }
private void DrawSlices(uint frame) { Debug.Assert(m_source != null); uint[] color_map = m_source.GetColorMap(); // retrieve image slices const ushort HORIZONTAL_RES = 256; const ushort VERTICAL_RES = 256; // get XY plane (assumes 1st axis is "X" and 2nd is "Y") Image3d imageXY = m_source.GetFrame(frame, m_bboxXY, new ushort[] { HORIZONTAL_RES, VERTICAL_RES, 1 }); ImageXY.Source = GenerateBitmap(imageXY, color_map); // get XZ plane (assumes 1st axis is "X" and 3rd is "Z") Image3d imageXZ = m_source.GetFrame(frame, m_bboxXZ, new ushort[] { HORIZONTAL_RES, VERTICAL_RES, 1 }); ImageXZ.Source = GenerateBitmap(imageXZ, color_map); // get ZY plane (assumes 2nd axis is "Y" and 3rd is "Z") Image3d imageZY = m_source.GetFrame(frame, m_bboxZY, new ushort[] { HORIZONTAL_RES, VERTICAL_RES, 1 }); ImageZY.Source = GenerateBitmap(imageZY, color_map); FrameTime.Text = "Frame time: " + imageXY.time; }
private WriteableBitmap GenerateBitmap(Image3d image, uint[] color_map) { WriteableBitmap bitmap = new WriteableBitmap(image.dims[0], image.dims[1], 96.0, 96.0, PixelFormats.Rgb24, null); bitmap.Lock(); unsafe { for (int y = 0; y < bitmap.Height; ++y) { for (int x = 0; x < bitmap.Width; ++x) { byte val = image.data[x + y * image.stride0]; byte *pixel = (byte *)bitmap.BackBuffer + x * (bitmap.Format.BitsPerPixel / 8) + y * bitmap.BackBufferStride; SetRGBVal(pixel, color_map[val]); } } } bitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight)); bitmap.Unlock(); return(bitmap); }
private void DrawImages(uint frame) { Debug.Assert(m_source != null); // retrieve image volume ushort[] max_res = new ushort[] { 128, 128, 128 }; Cart3dGeom bbox = m_source.GetBoundingBox(); if (Math.Abs(bbox.dir3_y) > Math.Abs(bbox.dir2_y)) { // swap 2nd & 3rd axis, so that the 2nd becomes predominately "Y" SwapVals(ref bbox.dir2_x, ref bbox.dir3_x); SwapVals(ref bbox.dir2_y, ref bbox.dir3_y); SwapVals(ref bbox.dir2_z, ref bbox.dir3_z); } // get XY plane (assumes 1st axis is "X" and 2nd is "Y") Cart3dGeom bboxXY = bbox; ushort[] max_resXY = new ushort[] { max_res[0], max_res[1], 1 }; bboxXY.origin_x = bboxXY.origin_x + bboxXY.dir3_x / 2; bboxXY.origin_y = bboxXY.origin_y + bboxXY.dir3_y / 2; bboxXY.origin_z = bboxXY.origin_z + bboxXY.dir3_z / 2; bboxXY.dir3_x = 0; bboxXY.dir3_y = 0; bboxXY.dir3_z = 0; Image3d imageXY = m_source.GetFrame(frame, bboxXY, max_resXY); // get XZ plane (assumes 1st axis is "X" and 3rd is "Z") Cart3dGeom bboxXZ = bbox; ushort[] max_resXZ = new ushort[] { max_res[0], max_res[2], 1 }; bboxXZ.origin_x = bboxXZ.origin_x + bboxXZ.dir2_x / 2; bboxXZ.origin_y = bboxXZ.origin_y + bboxXZ.dir2_y / 2; bboxXZ.origin_z = bboxXZ.origin_z + bboxXZ.dir2_z / 2; bboxXZ.dir2_x = bboxXZ.dir3_x; bboxXZ.dir2_y = bboxXZ.dir3_y; bboxXZ.dir2_z = bboxXZ.dir3_z; bboxXZ.dir3_x = 0; bboxXZ.dir3_y = 0; bboxXZ.dir3_z = 0; Image3d imageXZ = m_source.GetFrame(frame, bboxXZ, max_resXZ); // get YZ plane (assumes 2nd axis is "Y" and 3rd is "Z") Cart3dGeom bboxYZ = bbox; ushort[] max_resYZ = new ushort[] { max_res[1], max_res[2], 1 }; bboxYZ.origin_x = bboxYZ.origin_x + bboxYZ.dir1_x / 2; bboxYZ.origin_y = bboxYZ.origin_y + bboxYZ.dir1_y / 2; bboxYZ.origin_z = bboxYZ.origin_z + bboxYZ.dir1_z / 2; bboxYZ.dir1_x = bboxYZ.dir2_x; bboxYZ.dir1_y = bboxYZ.dir2_y; bboxYZ.dir1_z = bboxYZ.dir2_z; bboxYZ.dir2_x = bboxYZ.dir3_x; bboxYZ.dir2_y = bboxYZ.dir3_y; bboxYZ.dir2_z = bboxYZ.dir3_z; bboxYZ.dir3_x = 0; bboxYZ.dir3_y = 0; bboxYZ.dir3_z = 0; Image3d imageYZ = m_source.GetFrame(frame, bboxYZ, max_resYZ); FrameTime.Text = "Frame time: " + imageXY.time; uint[] color_map = m_source.GetColorMap(); ImageXY.Source = GenerateBitmap(imageXY, color_map); ImageXZ.Source = GenerateBitmap(imageXZ, color_map); ImageYZ.Source = GenerateBitmap(imageYZ, color_map); }
private void DrawImages(uint frame) { Debug.Assert(m_source != null); // retrieve image slices const ushort HORIZONTAL_RES = 256; const ushort VERTICAL_RES = 256; Cart3dGeom bbox = m_source.GetBoundingBox(); if (Math.Abs(bbox.dir3_y) > Math.Abs(bbox.dir2_y)) { // swap 2nd & 3rd axis, so that the 2nd becomes predominately "Y" SwapVals(ref bbox.dir2_x, ref bbox.dir3_x); SwapVals(ref bbox.dir2_y, ref bbox.dir3_y); SwapVals(ref bbox.dir2_z, ref bbox.dir3_z); } // extend bounding-box axes, so that dir1, dir2 & dir3 have equal length ExtendBoundingBox(ref bbox); // get XY plane (assumes 1st axis is "X" and 2nd is "Y") Cart3dGeom bboxXY = bbox; bboxXY.origin_x = bboxXY.origin_x + bboxXY.dir3_x / 2; bboxXY.origin_y = bboxXY.origin_y + bboxXY.dir3_y / 2; bboxXY.origin_z = bboxXY.origin_z + bboxXY.dir3_z / 2; bboxXY.dir3_x = 0; bboxXY.dir3_y = 0; bboxXY.dir3_z = 0; Image3d imageXY = m_source.GetFrame(frame, bboxXY, new ushort[] { HORIZONTAL_RES, VERTICAL_RES, 1 }); // get XZ plane (assumes 1st axis is "X" and 3rd is "Z") Cart3dGeom bboxXZ = bbox; bboxXZ.origin_x = bboxXZ.origin_x + bboxXZ.dir2_x / 2; bboxXZ.origin_y = bboxXZ.origin_y + bboxXZ.dir2_y / 2; bboxXZ.origin_z = bboxXZ.origin_z + bboxXZ.dir2_z / 2; bboxXZ.dir2_x = bboxXZ.dir3_x; bboxXZ.dir2_y = bboxXZ.dir3_y; bboxXZ.dir2_z = bboxXZ.dir3_z; bboxXZ.dir3_x = 0; bboxXZ.dir3_y = 0; bboxXZ.dir3_z = 0; Image3d imageXZ = m_source.GetFrame(frame, bboxXZ, new ushort[] { HORIZONTAL_RES, VERTICAL_RES, 1 }); // get ZY plane (assumes 2nd axis is "Y" and 3rd is "Z") Cart3dGeom bboxZY = bbox; bboxZY.origin_x = bbox.origin_x + bbox.dir1_x / 2; bboxZY.origin_y = bbox.origin_y + bbox.dir1_y / 2; bboxZY.origin_z = bbox.origin_z + bbox.dir1_z / 2; bboxZY.dir1_x = bbox.dir3_x; bboxZY.dir1_y = bbox.dir3_y; bboxZY.dir1_z = bbox.dir3_z; bboxZY.dir2_x = bbox.dir2_x; bboxZY.dir2_y = bbox.dir2_y; bboxZY.dir2_z = bbox.dir2_z; bboxZY.dir3_x = 0; bboxZY.dir3_y = 0; bboxZY.dir3_z = 0; Image3d imageZY = m_source.GetFrame(frame, bboxZY, new ushort[] { HORIZONTAL_RES, VERTICAL_RES, 1 }); FrameTime.Text = "Frame time: " + imageXY.time; uint[] color_map = m_source.GetColorMap(); ImageXY.Source = GenerateBitmap(imageXY, color_map); ImageXZ.Source = GenerateBitmap(imageXZ, color_map); ImageZY.Source = GenerateBitmap(imageZY, color_map); }