Re: [Gdcm2] Fwd: Select only dicom of the directory with Python
Cross-platform DICOM implementation
Brought to you by:
malat
From: Paulo H. J. A. <pau...@gm...> - 2008-05-16 12:49:12
|
Hi Mathieu, It worked. Thank you. Only one point below in the read. reader = gdcm.ImageReader() reader.SetFileName("C:\ > > \MyDicom.dcm") > if reader.Read(): #warning .Read will fail if DICOM file does not > contain an Image (=Pixel Data elt) > t1 = gdcm.Tag(0x0020, 0x0032) > ds = reader.GetFile().GetDataSet() > if ds.FindDataElement( t1 ): > print ds.GetDataElement( t1 ) Regards, Paulo Amorim 2008/5/16 Mathieu Malaterre <mat...@gm...>: > Hi Paulo, > > I'd suggest you have a look at > gdcm/Testing/Source/MediaStorageAndFileFormat/Python/TestModifyFields.py > > On Thu, May 15, 2008 at 8:35 PM, Paulo Henrique Junqueira Amorim > <pau...@gm...> wrote: > > Hi Mathieu, > > > > And to read and Show Information from 0x0020, 0x0032 with only a file? > > > > import gdcm > > ok > > > read = gdcm.ImageReader() > > how do you know for sure that this is going to be a DICOM file which > contains an Image ? If unusure, prefer a gdcm.Reader() > > > read.SetFileName("C:\\MyDicom.dcm") > > read.Read() > > ok. But you should check for the return value (True/False) > > > gdcm_scanner = gdcm.Scanner() > > > > t1 = gdcm.Tag(0x0020, 0x0032) > > gdcm_scanner.AddTag( t1) > > > > print gdcm_scanner.GetValue(read, t6) > > > gdcm.Scanner is meant to reading a large number of files. Since you > have already opened & read the entire file using gdcm.ImageReader, > simply check the value within the dataset: > > reader = gdcm.ImageReader() > reader.SetFileName("C:\\MyDicom.dcm") > if reader.Read(): #warning .Read will fail if DICOM file does not > contain an Image (=Pixel Data elt) > t1 = gdcm.Tag(0x0020, 0x0032) > ds = reader.GetDataSet() > if ds.FindDataElement( t1 ): > print ds.GetDataElement( t1 ) > > HTH > -- > Mathieu > |