[vtkusers] convert unsigned VTkimagedata to signed one

Ali Habib ali.mahmoud.habib at gmail.com
Sun Mar 7 14:21:42 EST 2010


Dear All,

I read DICOm data to VTK image data and display it but it give error that
"this filter requires unsigned char scalar " I want to convert the data to
unsigned char

the code use:

            vtk.vtkDICOMImageReader VDR = new vtk.vtkDICOMImageReader();
            VDR.SetDirectoryName(@"G:\Master
Degree\DataSet\case2\DICOM\PA1\ST1\SE2");
            VDR.SetDataOrigin(0, 0, 0);
            VDR.Update();

            // decrease the dataset data for large data preprocessing

            vtkImageShrink3D VIS = new vtkImageShrink3D();
            VIS.SetShrinkFactors(2, 2, 2);
            VIS.SetInputConnection(VDR.GetOutputPort());
            VIS.Update();

            vtkImageThreshold VIT = new vtkImageThreshold();
            VIT.ThresholdBetween(200, 2000);
            VIT.SetInputConnection(VIS.GetOutputPort());
            VIT.Update();

            ///// Start the creation of volume rendering

            //1. Gget the range of data
            vtk.vtkImageChangeInformation VIC = new
vtk.vtkImageChangeInformation();
            VIC.SetInput(VDR.GetOutput());
            VIC.CenterImageOn();
            VIC.Update();

            vtk.vtkImageData VoxelData = new vtk.vtkImageData();
            VoxelData = VIC.GetOutput();
            VoxelData.AllocateScalars();

            vtkImageActor imageActor = new vtkImageActor();
            imageActor.SetInput(VoxelData);


 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Create the RenderWindow, Renderer and both Actors
            //
            vtkRenderer ren1 = new vtkRenderer();
            vtkRenderWindow renWin = new vtkRenderWindow();
            renWin.AddRenderer(ren1);
            vtkRenderWindowInteractor iren = new
vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            // Add the actors to the renderer, set the background and size
            //
            ren1.AddActor(imageActor);
            ren1.SetBackground(.1, .2, .4);



            ren1.ResetCamera();
            ren1.ResetCameraClippingRange();

            renWin.Render();

Best regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100307/5a4feb79/attachment.htm>


More information about the vtkusers mailing list