Reputation: 45
how can I get spacing value from allready oppened file. I try his but it do not work exactly. I have to save a DICOM file.
vtkSmartPointer<vtkImageData> OutData = images[currentImageIndex];
meta->SetAttributeValue(DC::PixelSpacing, OutData->GetSpacing (double x, double y, double z);
Upvotes: 0
Views: 530
Reputation: 1344
You can get the spacing with OutData->GetOutput()->GetSpacing()
. If you want to save a DICOM file, this could be an approach (python):
#Read DICOM
reader = vtk.vtkDICOMImageReader()
reader.SetFileName("sample.dcm")
reader.Update()
spacing = reader.GetOutput().GetSpacing()
newimage = vtk.vtkImageData()
newimage.SetSpacing(spacing)
writer = vtk.vtkXMLImageDataWriter()
writer.SetFileName("sample.vti")
writer.SetInput(newimage)
writer.Write()
This actually saves to .vti file, because there is no class in VTK to save dicom file. But you can do this with other libraries, such as gdcm2vtk
Upvotes: 1