Пример #1
0
    def loadDicomInfo(self, dir, dimension):
        # Only available for special data (Need to modify for more universal usage)
        info = db.ImageInfo()
        data = dicom.read_file(dir)
        modality = data.Modality
        info.addData('modality', modality)
        if modality == 'MR' or modality == 'CT':
            ps = data.PixelSpacing
            if modality == 'MR':
                z = data.SpacingBetweenSlices
            else:
                z = data.SliceThickness
            if dimension == 3:
                resolution = [float(z), float(ps[0]), float(ps[1])]
            else:
                resolution = [float(ps[0]), float(ps[1])]   
            resolution = npy.array(resolution)
            info.addData('resolution', resolution)
            orientation = npy.array(map(float, data.ImageOrientationPatient))
            info.addData('orientation', orientation)
        elif modality == 'US':
            r = data[0x200d, 0x3303].value
            resolution = npy.array([float(r[2]), float(r[1]), float(r[0])])
            info.addData('resolution', resolution)
            orientation = npy.array(map(float, data[0x200d, 0x3d00].value[0][0x0020, 0x9116].value[0][0x200d, 0x3d16].value))
            info.addData('orientation', orientation)
            
        # To make the orientation of images compatible
        view, flip = db.getViewAndFlipFromOrientation(orientation, resolution.shape[0])
        info.addData('view', view)
        info.addData('flip', flip)

        return info
Пример #2
0
    def loadDicomInfo(self, dir, dimension):
        # Only available for special data (Need to modify for more universal usage)
        info = db.ImageInfo()
        data = dicom.read_file(dir)
        modality = data.Modality
        info.addData('modality', modality)
        if modality == 'MR' or modality == 'CT':
            ps = data.PixelSpacing
            if modality == 'MR':
                z = data.SpacingBetweenSlices
            else:
                z = data.SliceThickness
            if dimension == 3:
                resolution = [float(z), float(ps[0]), float(ps[1])]
            else:
                resolution = [float(ps[0]), float(ps[1])]   
            resolution = npy.array(resolution)
            info.addData('resolution', resolution)
            orientation = npy.array(map(float, data.ImageOrientationPatient))
            info.addData('orientation', orientation)
        elif modality == 'US':
            r = data[0x200d, 0x3303].value
            resolution = npy.array([float(r[2]), float(r[1]), float(r[0])])
            info.addData('resolution', resolution)
            orientation = npy.array(map(float, data[0x200d, 0x3d00].value[0][0x0020, 0x9116].value[0][0x200d, 0x3d16].value))
            info.addData('orientation', orientation)
            
        # To make the orientation of images compatible
        view, flip = db.getViewAndFlipFromOrientation(orientation, resolution.shape[0])
        info.addData('view', view)
        info.addData('flip', flip)

        return info
Пример #3
0
    def KeyPressCallback(self, obj, event):
        ch = self.parent.window_interactor.GetKeySym()
        if ch == 'Return':
            if (self.X1, self.Y1) == (self.X2, self.Y2):
                return

            point = npy.round(self.getAllPoint())
            if self.parent.dimension:
                max = npy.max(point, axis=0)
                min = npy.min(point, axis=0)
                bound = [(min[i], max[i] + 1) for i in range(2)]
                bound = bound[::-1]
            else:
                point[0, self.parent.view] = 0
                point[1,
                      self.parent.view] = self.parent.parent.getData().getData(
                      ).shape[0] - 1
                max = npy.max(point, axis=0)
                min = npy.min(point, axis=0)
                bound = [(min[i], max[i] + 1) for i in range(3)]
                bound = bound[::-1]

            info = db.ImageInfo(self.parent.parent.getData().getInfo().data)
            info.setName(None)
            if not self.parent.dimension:
                orientation = npy.array([1, 0, 0, 0, 1, 0])
                info.addData('orientation', orientation)
                resolution = self.parent.parent.getData().getResolution()[::-1]
                info.addData('resolution', resolution)
                view, flip = db.getViewAndFlipFromOrientation(
                    orientation, resolution.shape[0])
                info.addData('view', view)
                info.addData('flip', flip)
                info.addData(
                    'clip',
                    npy.array([
                        bound[0][0], bound[0][1], bound[1][0], bound[1][1],
                        bound[2][0], bound[2][1]
                    ]))
                data = db.BasicData(
                    data=self.parent.parent.getData().getData()[
                        bound[0][0]:bound[0][1], bound[1][0]:bound[1][1],
                        bound[2][0]:bound[2][1]],
                    info=info)
            else:
                info.addData(
                    'clip',
                    npy.array(
                        [bound[0][0], bound[0][1], bound[1][0], bound[1][1]]))
                data = db.BasicData(
                    data=self.parent.parent.getData().getData()[
                        bound[0][0]:bound[0][1], bound[1][0]:bound[1][1]],
                    info=info)

            self.parent.parent.gui.addNewDataView(data)
Пример #4
0
 def getInfo(self, res = [1.0, 1.0, 1.0], ori = 0):
     info = db.ImageInfo()
     info.addData('modality', 'MR') 
     resolution = npy.array(res)
     info.addData('resolution', resolution)
     if ori == 0: # z
         orientation = npy.array([1, 0, 0, 0, 1, 0])
     elif ori == 1: # y
         orientation = npy.array([1, 0, 0, 0, 0, -1])
     elif ori == 2: # x
         orientation = npy.array([0, 1, 0, 0, 0, -1])
     info.addData('orientation', orientation)
     
     view, flip = db.getViewAndFlipFromOrientation(orientation, resolution.shape[0])
     info.addData('view', view)
     info.addData('flip', flip)
     
     return info
Пример #5
0
    def getInfo(self, res=[1.0, 1.0, 1.0], ori=0):
        info = db.ImageInfo()
        info.addData('modality', 'MR')
        resolution = npy.array(res)
        info.addData('resolution', resolution)
        if ori == 0:  # z
            orientation = npy.array([1, 0, 0, 0, 1, 0])
        elif ori == 1:  # y
            orientation = npy.array([1, 0, 0, 0, 0, -1])
        elif ori == 2:  # x
            orientation = npy.array([0, 1, 0, 0, 0, -1])
        info.addData('orientation', orientation)

        view, flip = db.getViewAndFlipFromOrientation(orientation,
                                                      resolution.shape[0])
        info.addData('view', view)
        info.addData('flip', flip)

        return info
Пример #6
0
 def KeyPressCallback(self, obj, event):
     ch = self.parent.window_interactor.GetKeySym()
     if ch == 'Return':
         if (self.X1, self.Y1) == (self.X2, self.Y2):
             return
             
         point = npy.round(self.getAllPoint())
         if self.parent.dimension:
             max = npy.max(point, axis = 0)
             min = npy.min(point, axis = 0)
             bound = [(min[i], max[i] + 1) for i in range(2)]
             bound = bound[::-1]
         else:
             point[0, self.parent.view] = 0
             point[1, self.parent.view] = self.parent.parent.getData().getData().shape[0] - 1
             max = npy.max(point, axis = 0)
             min = npy.min(point, axis = 0)
             bound = [(min[i], max[i] + 1) for i in range(3)]
             bound = bound[::-1]
         
         info = db.ImageInfo(self.parent.parent.getData().getInfo().data)
         info.setName(None)
         if not self.parent.dimension:
             orientation = npy.array([1, 0, 0, 0, 1, 0])
             info.addData('orientation', orientation)
             resolution = self.parent.parent.getData().getResolution()[::-1]
             info.addData('resolution', resolution)
             view, flip = db.getViewAndFlipFromOrientation(orientation, resolution.shape[0])
             info.addData('view', view)
             info.addData('flip', flip)
             info.addData('clip', npy.array([bound[0][0], bound[0][1], bound[1][0], 
                 bound[1][1], bound[2][0], bound[2][1]]))
             data = db.BasicData(data = self.parent.parent.getData().getData()[bound[0][0]:bound[0][1], 
                 bound[1][0]:bound[1][1], bound[2][0]:bound[2][1]], info = info)
         else:
             info.addData('clip', npy.array([bound[0][0], bound[0][1], bound[1][0], bound[1][1]]))
             data = db.BasicData(data = self.parent.parent.getData().getData()[bound[0][0]:bound[0][1], 
                 bound[1][0]:bound[1][1]], info = info)
             
         self.parent.parent.gui.addNewDataView(data)