[vtkusers] Save vtkImageReslice result to bitmap.

庄凌峰 jxdw_zlf at yahoo.com.cn
Thu Oct 29 05:19:02 EDT 2009


Hello
I am trying to save resliced result to local bitmap file. But it gives me a picture filled with white color. I can see the correct result if use vtkImageViewer to view it. My input is mhd file. Its content is :
  ObjectType = Image
  NDims = 3
  BinaryData = True
  BinaryDataByteOrderMSB = False
  CompressedData = False
  TransformMatrix = 1 0 0 0 1 0 0 0 1
  Offset = 0 0 0
  CenterOfRotation = 0 0 0
  ElementSpacing = 0.390625 0.390625 0.75
  DimSize = 512 512 227
  ElementType = MET_UCHAR
  ElementDataFile = CTRaw.raw

My test program is:
            vtk.vtkMetaImageReader v16 = new vtk.vtkMetaImageReader();
            v16.SetFileName(@"C:\vtk-dotnet\vtkdata-5.4.2\CTRaw.mhd");
            v16.Update();
            vtk.vtkMetaImageReader reader1 = v16;
            vtkImageCast readerImageCast = new vtkImageCast();
            readerImageCast.SetInputConnection(reader1.GetOutputPort());
            readerImageCast.SetOutputScalarTypeToUnsignedInt();
            readerImageCast.ClampOverflowOn();
            vtkTransform t1 = new vtkTransform();
            t1.PostMultiply();
            t1.RotateX(45);
            t1.RotateY(45);
            t1.RotateZ(30);
            vtkImageReslice res = new vtkImageReslice();
            res.SetInputConnection(readerImageCast.GetOutputPort());
            res.SetResliceAxesDirectionCosines(0, -1, 0, 0, 0, -1, 1, 0, 0);
            res.SetResliceAxesOrigin(0, 0, 0);
            res.SetResliceTransform(t1);
            res.InterpolateOn();
            res.SetInterpolationModeToCubic();
            res.SetOutputSpacing(1, 1, 1);
            res.SetBackgroundLevel(1023);
            vtkImageShiftScale m_displayImage = new vtkImageShiftScale();
            m_displayImage.SetInput(res.GetOutput());
            m_displayImage.SetOutputScalarTypeToUnsignedChar();
            vtkImageMapToWindowLevelColors m_displayWindowLevelColorsImage = new vtkImageMapToWindowLevelColors();
            m_displayWindowLevelColorsImage.SetInput(m_displayImage.GetOutput());
            m_displayWindowLevelColorsImage.SetWindow(200);
            m_displayWindowLevelColorsImage.SetLevel(750);
            vtkBMPWriter writer = new vtkBMPWriter();
            writer.SetInput(m_displayImage.GetOutput());
            writer.SetFileName("c:/testt.bmp");
            writer.Update();

Thanks!

zlf


      ___________________________________________________________ 
  好玩贺卡等你发,邮箱贺卡全新上线! 
http://card.mail.cn.yahoo.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091029/fc9929f8/attachment.htm>


More information about the vtkusers mailing list