How to use the pydicom.dicomio.read_file function in pydicom

To help you get started, we’ve selected a few pydicom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pydicom / pydicom / tests / test_charset.py View on Github external
def testLatin1(self):
        """charset: can read and decode latin_1 file........................"""
        ds = dicomio.read_file(latin1_file)
        ds.decode()
        # Make sure don't get unicode encode error on converting to string
        expected = u'Buc^J\xe9r\xf4me'
        got = ds.PatientName
        self.assertEqual(expected, got,
                         "Expected %r, got %r" % (expected, got))
github pydicom / pydicom / tests / test_charset.py View on Github external
def testExplicitISO2022_IR6(self):
        """charset: can decode file with multi-valued data elements........."""
        ds = dicomio.read_file(explicit_ir6_file)
        ds.decode()
github pydicom / pydicom / tests / test_dataset.py View on Github external
def testEqualityFileMeta(self):
        """Dataset: equality returns correct value if with metadata"""
        d = read_file(self.test_file)
        e = read_file(self.test_file)
        self.assertTrue(d == e)

        e.is_implicit_VR = not e.is_implicit_VR
        self.assertFalse(d == e)

        e.is_implicit_VR = not e.is_implicit_VR
        self.assertTrue(d == e)
        e.is_little_endian = not e.is_little_endian
        self.assertFalse(d == e)

        e.is_little_endian = not e.is_little_endian
        self.assertTrue(d == e)
        e.filename = 'test_filename.dcm'
        self.assertFalse(d == e)
github ericspod / Eidolon / eidolon / plugins / DicomPlugin.py View on Github external
def testSaveLoadPlane(self):
        self.plugin.saveObject(self.plane,self.tempdir)
        firstfile=first(glob.glob(self.tempdir+'/*'))
        read_file(firstfile)
        
        eidolon.printFlush(self.planearr)
github ericspod / Eidolon / eidolon / plugins / DicomPlugin.py View on Github external
def loadDicomVolume(self,filename,name=None,interval=1.0,toffset=0.0,position=vec3(),rot=rotator(),task=None):
        '''Load a single DICOM file containing a 3D or 4D image volume (ie. ultrasound) using nonstandard tags.'''
        dcm=read_file(filename)
        name=name or eidolon.splitPathExt(filename)[1]

        NT=NonstandardTags
        spacing=vec3(dcm[NT.USpixdimx].value,dcm[NT.USpixdimy].value,dcm[NT.USpixdimz].value)*10
        dimsize=(dcm[NT.USnumframes].value,dcm[NT.USdepth].value,dcm[NT.USheight].value,dcm[NT.USwidth].value)
        pixeldata=dcm[NT.USpixeldata].value

        assert len(pixeldata)==eidolon.prod(dimsize), 'Pixel data dimension is %i, should be %i'%(len(pixeldata),eidolon.prod(dimsize))

        dat=np.ndarray(dimsize,dtype=np.uint8,buffer=pixeldata,order='C')
        dat=np.transpose(dat,(3,2,1,0))

        obj=self.createObjectFromArray(name,dat,interval,toffset,position,rot*rotator(eidolon.halfpi,0,0),spacing,task=task)
        obj.source=convertToDict(dcm)
        return obj
github spyder-ide / spyder / spyder / plugins / io_dcm / plugin.py View on Github external
def load_dicom(filename):
        try:
            name = osp.splitext(osp.basename(filename))[0]
            try:
                data = dicomio.read_file(filename, force=True)
            except TypeError:
                data = dicomio.read_file(filename)
            arr = data.pixel_array
            return {name: arr}, None
        except Exception as error:
            return None, str(error)
except ImportError:
github ericspod / DicomBrowser / DicomBrowser / DicomBrowser.py View on Github external
def getTagObject(self,index):
        '''Get the object storing tag information from Dicom file at the given index.'''
        if index not in self.tagcache:
            dcm=dicomio.read_file(self.filenames[index],stop_before_pixels=True)
            self.tagcache[index]=dcm
            
        return self.tagcache[index]
github ericspod / DicomBrowser / DicomBrowser / dicom.py View on Github external
def getTagObject(self, index):
        """Get the object storing tag information from Dicom file at the given index."""
        if index not in self.tagcache:
            dcm = dicomio.read_file(self.filenames[index], stop_before_pixels=True)
            self.tagcache[index] = dcm

        return self.tagcache[index]
github ericspod / Eidolon / eidolon / plugins / DicomPlugin.py View on Github external
def loadDicomZipFile(filename, includeTags=False):
    dds=DicomDataset(filename)
    
    with zipfile.ZipFile(filename) as z:
        for n in z.namelist():
            s=BytesIO(z.read(n))
            try:
                ds=read_file(s)
            except:
                pass # ignore files which aren't Dicom files
            else:
                dsi=DicomSharedImage(n,dcm=ds,includeTags=includeTags)
                
                series=dds.getSeries(ds.SeriesInstanceUID,True)
                series.addFile(n)
                series.addSharedImages([dsi])
                series.desc=series.desc or str(ds.get('SeriesDescription',series.desc)).strip()
                series.seriesNum=series.seriesNum or int(ds.get('SeriesNumber',series.seriesNum))
            
    return dds
github ericspod / Eidolon / eidolon / plugins / DicomPlugin.py View on Github external
def loadDicomFile(self,index):
        return read_file(os.path.join(self.parent.rootdir,self.filenames[index]))