vtkDICOMImageReader(): Anyway to change the metadata?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

vtkDICOMImageReader(): Anyway to change the metadata?

sonamwangyal
Hello! 

This is my first post in this community and just as a heads up I am a complete newbie. I am currently working on a project to segment ventricles from MRI scans of the brain (in MATLAB). I wanted to then extract the surface using vtkDiscreteMarchingCubes() and write it into an STL file using vtkSTLWriter(). 

My problem is with the PixelSpacing, the documentation says if there are multiple DICOM images then the 'z' value is the Spacing Between the Slices. But I am receiving (0.859375, 0.859375, 0.0). I don't know why it is giving me a 0.0, it should be a 5. I have tried with an single DICOM and it works properly it gave me a Slice Thickness which coincidentally is the same value as the Spacing Between the Slices. 

SO MY QUESTION IS: is there anyway to manually change the value? My code is down below, THANKS FOR YOUR HELP! 

import vtk 

PathDicom = "./DICOMs/" 
reader = vtk.vtkDICOMImageReader() 
reader.SetDirectoryName(PathDicom) 
reader.Update() 

print(reader.GetPixelSpacing()) 

dmc = vtk.vtkDiscreteMarchingCubes() 
dmc.SetInputConnection(reader.GetOutputPort()) 
dmc.GenerateValues(1, 1, 1) 
dmc.Update() 

writer = vtk.vtkSTLWriter() 
writer.SetInputConnection(dmc.GetOutputPort()) 
writer.SetFileTypeToBinary() 
writer.SetFileName("ventricle.stl") 
writer.Write()

Cheers,
Sonam Wangyal
Electrical Engineering | BEng Candidate 
The Faculty of Engineering and Architectural Science
C: 647.779.2560


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtkDICOMImageReader(): Anyway to change the metadata?

David Gobbi
Hi Sonam,

The filter vtkImageChangeInformation can modify the spacing of the data:

ici = vtk.vtkImageChangeInformation()
ici.SetInputConnection(reader.GetOutputPort())
ici.SetOutputSpacing(0.859375, 0.859375, 5.0)

 - David

On Thu, Jul 13, 2017 at 11:19 AM, Sonam Wangyal <[hidden email]> wrote:
Hello! 

This is my first post in this community and just as a heads up I am a complete newbie. I am currently working on a project to segment ventricles from MRI scans of the brain (in MATLAB). I wanted to then extract the surface using vtkDiscreteMarchingCubes() and write it into an STL file using vtkSTLWriter(). 

My problem is with the PixelSpacing, the documentation says if there are multiple DICOM images then the 'z' value is the Spacing Between the Slices. But I am receiving (0.859375, 0.859375, 0.0). I don't know why it is giving me a 0.0, it should be a 5. I have tried with an single DICOM and it works properly it gave me a Slice Thickness which coincidentally is the same value as the Spacing Between the Slices. 

SO MY QUESTION IS: is there anyway to manually change the value? My code is down below, THANKS FOR YOUR HELP! 

import vtk 

PathDicom = "./DICOMs/" 
reader = vtk.vtkDICOMImageReader() 
reader.SetDirectoryName(PathDicom) 
reader.Update() 

print(reader.GetPixelSpacing()

dmc = vtk.vtkDiscreteMarchingCubes() 
dmc.SetInputConnection(reader.GetOutputPort()) 
dmc.GenerateValues(1, 1, 1) 
dmc.Update() 

writer = vtk.vtkSTLWriter() 
writer.SetInputConnection(dmc.GetOutputPort()) 
writer.SetFileTypeToBinary() 
writer.SetFileName("ventricle.stl") 
writer.Write()

Cheers,
Sonam Wangyal
Electrical Engineering | BEng Candidate 
The Faculty of Engineering and Architectural Science
C: <a href="tel:(647)%20779-2560" value="+16477792560" target="_blank">647.779.2560

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtkDICOMImageReader(): Anyway to change the metadata?

sonamwangyal
Thanks I used pydicom to get the metadata and used what you suggested and it worked!

Thank you!

Sent from my iPhone

On Jul 13, 2017, at 4:23 PM, David Gobbi [via VTK] <[hidden email]> wrote:

Hi Sonam,

The filter vtkImageChangeInformation can modify the spacing of the data:

ici = vtk.vtkImageChangeInformation()
ici.SetInputConnection(reader.GetOutputPort())
ici.SetOutputSpacing(0.859375, 0.859375, 5.0)

 - David

On Thu, Jul 13, 2017 at 11:19 AM, Sonam Wangyal <[hidden email]> wrote:
Hello! 

This is my first post in this community and just as a heads up I am a complete newbie. I am currently working on a project to segment ventricles from MRI scans of the brain (in MATLAB). I wanted to then extract the surface using vtkDiscreteMarchingCubes() and write it into an STL file using vtkSTLWriter(). 

My problem is with the PixelSpacing, the documentation says if there are multiple DICOM images then the 'z' value is the Spacing Between the Slices. But I am receiving (0.859375, 0.859375, 0.0). I don't know why it is giving me a 0.0, it should be a 5. I have tried with an single DICOM and it works properly it gave me a Slice Thickness which coincidentally is the same value as the Spacing Between the Slices. 

SO MY QUESTION IS: is there anyway to manually change the value? My code is down below, THANKS FOR YOUR HELP! 

import vtk 

PathDicom = "./DICOMs/" 
reader = vtk.vtkDICOMImageReader() 
reader.SetDirectoryName(PathDicom) 
reader.Update() 

print(reader.GetPixelSpacing()

dmc = vtk.vtkDiscreteMarchingCubes() 
dmc.SetInputConnection(reader.GetOutputPort()) 
dmc.GenerateValues(1, 1, 1) 
dmc.Update() 

writer = vtk.vtkSTLWriter() 
writer.SetInputConnection(dmc.GetOutputPort()) 
writer.SetFileTypeToBinary() 
writer.SetFileName("ventricle.stl") 
writer.Write()

Cheers,
Sonam Wangyal


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers



If you reply to this email, your message will be added to the discussion below:
http://vtk.1045678.n5.nabble.com/vtkDICOMImageReader-Anyway-to-change-the-metadata-tp5743964p5743965.html
To start a new topic under VTK - Users, email [hidden email]
To unsubscribe from VTK - Users, click here.
NAML
Loading...