[vtkusers] Problem using vtkDicomWriter

David Gobbi david.gobbi at gmail.com
Tue Jan 24 09:41:41 EST 2017


Hi Eddy,

Can you provide the code that you used to write the image with
vtkDICOMWriter?  Here is an example:
http://dgobbi.github.io/vtk-dicom/doc/api/image_writer.html

Creating an image with a loop that calls GetScalarPointer() for every pixel
is not very efficient, and casting to a "char *" when the data is "unsigned
short" is wrong: you are setting only 8 bits of each 16-bit pixel, while
leaving the other 8 bits uninitialized.  The vtkImageImport filter is a
better way of generating image data:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/ImageImport

 - David


On Tue, Jan 24, 2017 at 2:51 AM, Eddy Cappeau <edcpwk at gmail.com> wrote:

> Hi,
>
> I'd like to use the vtkDICOMWriter class to convert a vtkImage to a set of
> DICOM images.
>
> I've compile VTK with the vtkDICOM module enabled and followed the example
> from the pdf found on the github repository (http://dgobbi.github.io/vtk-
> dicom/doc/vtk-dicom.pdf).
>
>
> The image data is created like this :
>
>     auto  img = vtkSmartPointer < vtkImageData >::New();
>     img->SetOrigin(0, 0, 0);
>     img->SetDimensions(1024, 1024, numlayer);
>     img->SetSpacing(1, 1, 1);
>     img->AllocateScalars(VTK_UNSIGNED_SHORT, 1);
>
> and the data filled like this :
>
>            for (int n = 0; x < numlayer; n++) {
>                 for (int x = 0; x < 1024; x++) {
>                     for (int y = 0; y < 1024; y++) {
>                         char* pixel = static_cast<char*>(img->GetScalarPointer(x,
> y, n));
>                         pixel[0] = values[x][y];
>                     }
>
> I can load the converted result with paraview without problems.
> But with 3D Slicer, I can just load the first file of the serie and it
> display a blank image.
>
> What do I have to do to be able to load the images with both application ?
>
> Thanks,
>
> Eddy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170124/6527bb8a/attachment.html>


More information about the vtkusers mailing list