Beispiel #1
0
    def __call__(self, voxel, seg):
        shape = voxel.shape
        voxel = voxel / 255. - 1
        if self.train:
            if self.move is not None:
                center = random_center(shape, self.move)
            else:
                center = np.array(shape) // 2
            voxel_ret = crop(voxel, center, self.size)
            seg_ret = crop(seg, center, self.size)

            angle = np.random.randint(4, size=3)
            voxel_ret = rotation(voxel_ret, angle=angle)
            seg_ret = rotation(seg_ret, angle=angle)

            axis = np.random.randint(4) - 1
            voxel_ret = reflection(voxel_ret, axis=axis)
            seg_ret = reflection(seg_ret, axis=axis)
        else:
            center = np.array(shape) // 2
            voxel_ret = crop(voxel, center, self.size)
            seg_ret = crop(seg, center, self.size)

        if self.copy_channels:
            return np.stack([voxel_ret,voxel_ret,voxel_ret],0).astype(np.float32), \
                    np.expand_dims(seg_ret,0).astype(np.float32)
        else:
            return np.expand_dims(voxel_ret, 0).astype(np.float32), \
                    np.expand_dims(seg_ret,0).astype(np.float32)
Beispiel #2
0
    def __call__(self, ct):
        voxel = ct['image']
        voxel = np.expand_dims(voxel, 0).repeat(3, axis=0)
        y = ct['coarse_mask']
        shape = voxel.shape[1:]  # 120*120*120
        center = random_center_mask_mood(y)

        voxel_ret, crop_pos = crop_at_zyx_with_dhw(voxel, center, self.size,
                                                   self.fill_with)

        angle = np.random.randint(4, size=3)
        voxel_ret = np.stack([
            rotation(voxel_ret[0], angle=angle),
            rotation(voxel_ret[1], angle=angle),
            rotation(voxel_ret[2], angle=angle)
        ], 0)

        axis = np.random.randint(4) - 1
        voxel_ret = np.stack([
            reflection(voxel_ret[0], axis=axis),
            reflection(voxel_ret[1], axis=axis),
            reflection(voxel_ret[2], axis=axis)
        ], 0)

        return voxel_ret
Beispiel #3
0
    def __call__(self, voxel, name):
        shape = voxel.shape[1:]  # 3 dims
        y = np.load(
            os.path.join(self.data_path, 'roi/roi/labels',
                         name + '.npz'))['arr']
        loc = name.split('_')[-1]
        if loc == 'L':
            lb = 1 if 3 in y else 0
        elif loc == 'R':
            lb = 1 if 4 in y else 0
        else:
            print('error')

        if self.move is not None:
            center = random_center(shape, self.move)
        else:
            center = np.array(shape) // 2
        voxel_ret = crop(voxel, center, self.size)
        angle = np.random.randint(4, size=3)
        voxel_ret = np.stack([
            rotation(voxel_ret[0], angle=angle),
            rotation(voxel_ret[1], angle=angle),
            rotation(voxel_ret[2], angle=angle)
        ], 0)

        axis = np.random.randint(4) - 1
        voxel_ret = np.stack([
            reflection(voxel_ret[0], axis=axis),
            reflection(voxel_ret[1], axis=axis),
            reflection(voxel_ret[2], axis=axis)
        ], 0)

        return voxel_ret, lb
    def __call__(self, voxel, seg):
        shape = voxel.shape
        voxel = voxel / 255.0 - 1
        if self.train:
            if self.move is not None:
                center = random_center(shape, self.move)
            else:
                center = np.array(shape) // 2
            voxel_ret = crop(voxel, center, self.size)
            seg_ret = crop(seg, center, self.size)

            angle = np.random.randint(4, size=3)
            voxel_ret = rotation(voxel_ret, angle=angle)
            seg_ret = rotation(seg_ret, angle=angle)

            axis = np.random.randint(4) - 1
            voxel_ret = reflection(voxel_ret, axis=axis)
            seg_ret = reflection(seg_ret, axis=axis)
        else:
            center = np.array(shape) // 2
            voxel_ret = crop(voxel, center, self.size)
            seg_ret = crop(seg, center, self.size)

        # as resnet expects 3 channel input, then batch dimension is done in DataLoader
        if self.copy_channels:
            return np.stack([voxel_ret, voxel_ret, voxel_ret], 0).astype(
                np.float32), np.expand_dims(seg_ret, 0).astype(np.float32)
        else:
            return np.expand_dims(voxel_ret,
                                  0).astype(np.float32), np.expand_dims(
                                      seg_ret, 0).astype(np.float32)
def cone(d, h, rotation_angle):
    x, y, z = np.indices((d, d, h))
    r = np.linspace(0, d / 2, h)
    r = np.tile(r.reshape(1, 1, h), (d, d, 1))
    voxel = np.sqrt((x - (d - 1) / 2)**2 + (y - (d - 1) / 2)**2) <= r
    voxel = rotation(voxel, rotation_angle)
    return voxel
def pyramid(a, h, rotation_angle):
    x, y, z = np.indices((a, a, h))
    r = np.linspace(0, a / 2, h)
    r = np.tile(r.reshape(1, 1, h), (a, a, 1))
    voxel = np.maximum(np.abs(x - (a - 1) / 2), np.abs(y - (a - 1) / 2)) <= r
    voxel = rotation(voxel, rotation_angle)
    return voxel