示例#1
0
    def overlay_test(self):
        # filename =
        # r'c:\Data\kky\pro mechaniku 21.12.2012\53009707\Export0000\SR0000'
        # filename = r'c:\Data\kky\pro mechaniku
        # 21.12.2012\52496602\Export0001\SR0000'
        # filename = r'c:\Data\kky\pro mechaniku
        # 21.12.2012\54559730\Export0000\SR0000'
        filename = r'c:\Data\kky\pro mechaniku 21.12.2012\53596059\Export0000\SR0000'  # noqa
        # dcr = dcmreaddata.DicomReader(
        # r'c:\Data\kky\pro mechaniku 21.12.2012\52496602\Export0001\SR0000')
        dcr = dcmreaddata.DicomReader(filename)
        data3d = dcr.get_3Ddata()
        overlay = dcr.get_overlay()
        win_w = 350
        win_c = 50
        min_w = win_c - (win_w / 2.)
        max_w = win_c + (win_w / 2.)

        for key in overlay.keys():
            overlay = overlay[key]

            for i in range(overlay.shape[0]):
                plt.figure(), plt.gray()
                plt.subplot(121), plt.imshow(data3d[i, :, :],
                                             vmin=min_w,
                                             vmax=max_w)
                plt.subplot(122), plt.imshow(overlay[i, :, :])
                cv2.imwrite(filename + '/overlay_%i.png' % i, data3d[i, :, :])

        plt.show()
示例#2
0
文件: dicom2fem.py 项目: rc/dicom2fem
    def loadDcmDir(self):
        self.statusBar().showMessage('Reading DICOM directory...')
        QApplication.processEvents()

        if self.dcmdir is None:
            self.dcmdir = dcmreader.get_dcmdir_qt(app=True)

        if self.dcmdir is not None:
            dcr = dcmreader.DicomReader(os.path.abspath(self.dcmdir),
                                        qt_app=self)
        else:
            self.statusBar().showMessage('No DICOM directory specified!')
            return

        if dcr.validData():
            self.dcm_3Ddata = dcr.get_3Ddata()
            self.dcm_metadata = dcr.get_metaData()
            self.voxel_sizemm = np.array(self.dcm_metadata['voxelsizemm'])

            self.setVoxelVolume(self.voxel_sizemm)
            self.setLabelText(self.text_dcm_dir, self.dcmdir)
            self.setLabelText(self.text_dcm_data, self.getDcmInfo())
            self.statusBar().showMessage('Ready')
            self.setLabelText(self.text_seg_in, 'DICOM reader')
            
        else:
            self.statusBar().showMessage('No DICOM data in direcotry!')
示例#3
0
    def loadDcmDir(self, event=None, filename=None):
        self.statusBar().showMessage('Loading DICOM data...')
        QApplication.processEvents()

        # TODO uninteractive Serie selection

        #self.data3d, self.metadata = dcmr.dcm_read_from_dir(datadir)
        datadir = dcmr.get_dcmdir_qt(self.qt_app)

        # @TODO dialog v qt
        reader = dcmr.DicomReader(datadir)  #, qt_app=self.qt_app)
        self.data3d = reader.get_3Ddata()
        self.metadata = reader.get_metaData()
        self.inps['series_number'] = reader.series_number
        self.inps['datadir'] = datadir

        self.statusBar().showMessage('DICOM data loaded')
示例#4
0
    def __ReadFromDirectory(self, datapath, start, stop, step):
        if dcmr.is_dicom_dir(datapath):  # reading dicom
            logger.debug('Dir - DICOM')
            reader = dcmr.DicomReader(datapath, qt_app=None, gui=True)
            data3d = reader.get_3Ddata(start, stop, step)
            metadata = reader.get_metaData()
            metadata['series_number'] = reader.series_number
            metadata['datadir'] = datapath
            self.overlay_fcn = reader.get_overlay
        else:  # reading image sequence
            import SimpleITK as sitk
            logger.debug('Dir - Image sequence')

            logger.debug('Getting list of readable files...')
            flist = []
            for f in os.listdir(datapath):
                try:
                    sitk.ReadImage(os.path.join(datapath, f))
                except:
                    logger.warning("Cant load file: " + str(f))
                    continue
                flist.append(os.path.join(datapath, f))
            flist.sort()

            logger.debug('Reading image data...')
            image = sitk.ReadImage(flist)
            logger.debug('Getting numpy array from image data...')
            data3d = sitk.GetArrayFromImage(image)

            metadata = {}  # reader.get_metaData()
            metadata['series_number'] = 0  # reader.series_number
            metadata['datadir'] = datapath
            spacing = image.GetSpacing()
            metadata['voxelsize_mm'] = [
                spacing[2],
                spacing[0],
                spacing[1],
            ]

        return data3d, metadata
 def import_dir(self, datadir):
     reader = dcmr.DicomReader(datadir)
     self.data3d = reader.get_3Ddata()
     self.metadata = reader.get_metaData()
     #self.data3d, self.metadata = dcmr.dcm_read_from_dir(datadir)
     self.voxelsize_mm = np.array(self.metadata['voxelsize_mm'])