X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=gdcmPython%2Fdemo%2FvtkGdcmDemo.py;h=128029604bfc319c885ac428e009e2c78e79e1c9;hb=4399e9fed374a2dcc7f1ab98ec7b5af5f7982aca;hp=142066a1b8d650b999ddb193cc759a735a567998;hpb=297fe0ed9c4b5535b92c36615acff0b059209ed3;p=gdcm.git diff --git a/gdcmPython/demo/vtkGdcmDemo.py b/gdcmPython/demo/vtkGdcmDemo.py index 142066a1..12802960 100644 --- a/gdcmPython/demo/vtkGdcmDemo.py +++ b/gdcmPython/demo/vtkGdcmDemo.py @@ -1,4 +1,11 @@ -## 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 @@ -33,9 +40,9 @@ class vtkHistogram: 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): @@ -172,10 +179,10 @@ if not check.IsReadable(): 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 @@ -187,9 +194,12 @@ try: 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