I need to make a conversion from a DICOM image to a JPG/PNG and save the image using VTK, but the image that I produce does not match the original.
I know I need rescaling the pixels of the image to convert it but I do not know how. Does anyone know how I can do the conversion properly?
Below, my code in python:
from vtk import *
reader = vtkDICOMImageReader()
reader.SetFileName('image.dcm')
reader.Update()
castFilter = vtkImageCast()
castFilter.SetOutputScalarTypeToUnsignedChar()
castFilter.SetInputConnection(reader.GetOutputPort())
castFilter.Update()
writer = vtkJPEGWriter()
writer.SetFileName('output.jpg')
writer.SetInputConnection(castFilter.GetOutputPort())
writer.Write()