[vtkusers] Creating a vtkImageData from scratch reading DICOM files with DCMTK

Jesús Spí­nola jspinola at gmail.com
Thu Aug 16 09:47:07 EDT 2007


Hi vtkusers,

I want to read some DICOM files into one vtkImageData. To read the pixel
data from the DICOM files I want to use the DCMTK libraries. The
vtkImageData object will contain several DICOM images so I want to load the
pixel data into vtkImageData file by file.

First I allocate the vtkImageData and then I load the files in a bucle from
dcmtk (DicomImage class) to the vtkImageData object. The images are loaded
correctly by dcmtk ( I dumped the images in a png file and they're ok ) but
when I want to view the images with vtkImageViewer2 they are completely
dark, so it seems no data is loaded at all. Following there's the code
snippet I use to do that. I also tried to read the pixel data with
DcmDataset::findAndGetUint16Array(DCM_PixelData,..) instead of DicomImage,
but with no success.

Has anyone any suggestions of what I'm probably missing or doing wrong?

// first we allocate the data
m_imageDataVTK = vtkImageData::New();
m_imageDataVTK->SetOrigin( origin );
m_imageDataVTK->SetSpacing( spacing );
m_imageDataVTK->SetDimensions( rows, columns, slices );
m_imageDataVTK->SetScalarTypeToUnsignedShort(); // the data will be 16 bit
m_imageDataVTK->SetNumberOfScalarComponents(1);
m_imageDataVTK->AllocateScalars();

// now we load all the images
int zSlice = 0;

    foreach( Image *image, m_imageSet )
    {
        DicomImage *dicomImage = new DicomImage( qPrintable(
image->getPath() ) ); // we load a new Image
        if( dicomImage != NULL )
        {
            if( dicomImage->getStatus() == EIS_Normal )
            {
                dicomImage->setMinMaxWindow();
                if( dicomImage->getOutputData(16) != NULL )
                {
                    // we copy the data in the dcmtk buffer to the
vtkImageData one
                    memcpy((unsigned short
*)m_imageDataVTK->GetScalarPointer(0,0,zSlice), (unsigned short
*)dicomImage->getOutputData(16), dicomImage->getOutputDataSize() );
                    dicomImage->deleteOutputData();
                    m_imageDataVTK->Modified();
                }
        }
        zSlice++;
    }

Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070816/b315b436/attachment.htm>


More information about the vtkusers mailing list