[vtkusers] Creating a vtkImageData from scratch reading DICOM files with DCMTK
Jesús Spínola
jspinola at gmail.com
Thu Aug 16 13:31:52 EDT 2007
I just realized the problem wasn't in copying the data, I missed some
parameters for the vtkImageViewer camera in my test program :/
Now I can load the images, but they don't look very well, maybe it's about
the bytes I'm allocating for the image and the buffers, or something related
with the window level functions.
Thanks for your reply
On 8/16/07, Mark Wyszomierski <markww at gmail.com> wrote:
>
> Jesus, I always use DcmFileFormat and haven't had problems with it and
> vtkImageData. I've never tried with DicomImage. I thought DicomImage
> does window level / rescale slope/intercept transformations
> automatically which is why I don't use it.
>
> Anyway I think the DICOM object will give you the image data top to
> bottom, but VTK works in cartesian coordinates, bottom to top. So you
> probably have to setup a pixel loop to do the work of reading the
> DICOM image backwards. I usually do something like:
>
> DcmFileFormat dcm;
> dcm.loadFile("C:\\test.dcm");
> const unsigned short* p = NULL;
> dcm.getDataset()->findAndGetUint16Array(DCM_PixelData, p);
>
> // Then copy over each pixel value from p in a pixel loop but bottom
> to top into your vtkImageData object.
>
> Like I said I've been doing that for awhile without any problems, hope
> that helps somewhat,
>
> Mark
>
>
>
>
>
> On 8/16/07, Jesús Spínola <jspinola at gmail.com> wrote:
> > 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!
> >
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070816/dd1ac3ce/attachment.htm>
More information about the vtkusers
mailing list