-## A small demo that displays with VTK an image parsed with gdcm.
+## A small demo that displays with VTK a dicom image parsed with gdcm.
+## Warning: the parsing of header of the dicom file is done with gdcm
+## but the process of in-memory loading of the image is performed
+## by vtkImageReader (classical vtk operator). Since vtkImageReader
+## has no special knowledge of Dicom file format, this demo
+## will only work for a restrained sub-set of Dicom files (basically
+## non compressed and with "HighBit + 1 != BitsStored").
+## When those conditions are not met try using vtkgdcmReader.py...
import sys
import vtk
from gdcmPython import gdcmHeader
self.ComputeHisto()
self.__CumulHisto = []
histo = self.__Histo.GetOutput()
- self.__CumulHisto.append(int(histo.GetScalarComponentAsFloat(0,0,0,0)))
+ self.__CumulHisto.append(int(histo.GetScalarComponentAsDouble(0,0,0,0)))
for i in range(1, self.__NumberOfBins):
- value = int(histo.GetScalarComponentAsFloat(i,0,0,0))
+ value = int(histo.GetScalarComponentAsDouble(i,0,0,0))
self.__CumulHisto.append( self.__CumulHisto[i-1] + value)
def GetTruncateLevels(self, LostPercentage):
print "The ", FileName, " file is not "
print " readable with gdcm. Sorry."
sys.exit()
-check = check.GetPubElVal()
+check = check.GetEntry()
try:
- BitsAlloc = check["Bits Allocated"]
- if len(BitsAlloc) == 0 or BitsAlloc == "gdcm::Unfound":
+ HighBit = check["High Bit"]
+ if len(HighBit) == 0 or HighBit == "gdcm::Unfound":
raise KeyError
except KeyError:
print "Gdcm couldn't find the Bits Allocated Dicom tag in file ", FileName
except KeyError:
print "Gdcm couldn't find the Bits Stored Dicom tag in file ", FileName
sys.exit()
-if BitsAlloc != BitsStored:
+if int(HighBit) + 1 != int(BitsStored):
print "vtkImageReader cannot read the file ", FileName
- print " because the Bits Allocated and the Bits stored don't match."
+ print " because the High Bit is offseted from the BitsStored."
+ print " You should consider using vtkGdcmReader as opposed to the"
+ print " vtkImageReader python class present in this demo. Please"
+ print " see gdcmPython/demo/vtkGdcmReader.py for a demo."
sys.exit()
### Display in a vtk RenderWindow