[vtkusers] Creating a vtkImageData from scratch reading DICOM files with DCMTK
Emmanouil Moschidis
moshman65 at yahoo.com
Thu Aug 16 14:37:15 EDT 2007
HI , I had more or less the same problem some time ago. I was reading images within OsiriX which also uses DCMTK and I ended up with the following way of reading and writing from DCMTK images to vtkImageData. In my way of doing that I have a pointer to the DCMTK pixels... note that I am programming in Objective C++ so some points may not be so clear but I think what you need to check out is the loop where I am reading the pixels from the DCMTK images with the help of the pointer (fImage) and load them in the vtkImageData by using the following line of code:
image->GetPointData()->GetScalars()->SetTuple1(pixelID, pixelValue);
for me it worked fine... this is the snippet of my code:
vtkImageData *image=vtkImageData::New();
image->SetOrigin( [[[[filter viewerController] pixList]objectAtIndex:i]originX], [[[[filter viewerController] pixList]objectAtIndex:i]originY], [[[[filter viewerController] pixList]objectAtIndex:i]originZ]);
image->SetExtent(0,(newwidth-1),0,(newheight-1),0,0);
image->SetWholeExtent(0,(newwidth-1),0,(newheight-1),0,0);
image->SetUpdateExtent(0,(newwidth-1),0,(newheight-1),0,0);
image->SetUpdateExtentToWholeExtent();
image->AllocateScalars();
int counter=0;
for(int y=0;y<newheight;y++)
{
for(int x=0;x<newwidth;x++)
{
image->GetPointData()->GetScalars()->SetTuple1(counter, fImage[newwidth*y+x]);
counter++;
}
}
image->Update();
Also note that due to the different coordinate system (DICOM and VTK) the resulting image will be flipped in the Y axis... Since the origin in DICOM is the upper left corner and the VT origin the lower left corner, the first top line of pixels that will be read from the DICOM image will be placed as the first bottom line of pixels in the vtkImageData image...
HTH
Emmanouil
---------------------------------
Pinpoint customers who are looking for what you sell.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070816/eca735ba/attachment.htm>
More information about the vtkusers
mailing list