def load_slices(data_path, case_list):
    img_list = []
    pan_list = []
    les_list = []
    for ID in case_list:
        img_path = data_path + '/' + ID + '/ctscan.npy'
        pan_path = data_path + '/' + ID + '/pancreas.npy'
        pancreas = np.load(pan_path)
        pancreas = smoothing(pancreas)
        img = np.load(img_path)
        img = windowing(img)
        img = minmax_normalization(img)
        lesion = np.zeros(img.shape)
        if ID[:2] != 'NP' and ID[:2] != 'AD':
            les_path = data_path + '/' + ID + '/lesion.npy'
            lesion = np.load(les_path)
            pancreas[np.where(lesion == 1)] = 1

        # pancreas is union of pancreas and lesion by hands.
        img_pan = img * pancreas
        img_list.append(img)
        pan_list.append(img_pan)
        les_list.append(lesion)

    return img_list, pan_list, les_list
Ejemplo n.º 2
0
    def preprocessing_test(self, image, pancreas, lesion):
        from skimage import morphology

        if self.data_type == 'tcia':
            image = image[:, ::-1, :]
            pancreas = pancreas[:, ::-1, :]
            lesion = lesion[:, ::-1, :]
            pancreas = smoothing(pancreas)
            lesion = smoothing(lesion)
        elif self.data_type == 'msd':
            image = image[::-1, ::-1, :]
            pancreas = pancreas[::-1, ::-1, :]
            lesion = lesion[::-1, ::-1, :]
        elif self.data_type == 'ntuh':
            image = image[::-1, ::-1, :]
            pancreas = pancreas[::-1, ::-1, :]
            lesion = lesion[::-1, ::-1, :]

        pancreas = morphology.dilation(pancreas, np.ones([3, 3, 1]))
        lesion = morphology.dilation(lesion, np.ones([3, 3, 1]))

        image = windowing(image)
        image = pancreas_normalization(image, pancreas, lesion)

        return image, pancreas, lesion
Ejemplo n.º 3
0
def patch_generator(data_path,
                    tumor_id,
                    patch_size=50,
                    dilation=[5, 5, 5],
                    add_mask=True,
                    stride=30,
                    threshold=0.5,
                    max_amount=1000):
    """
    Usage: Complete process of patch generating

    Parameters
    ----------
    data_path (str): The path for the box data
    tumor_id (str): The target ID
                    Example: 'PT1'
    patch_size (int): Patch size, default to 50
    dilation (int): the dilation of non-lesion region

    Returns
    -------
    List: each content is a 2D patch
    List: each content is a label

    """

    X = []
    Y = []

    img_path = data_path + '/' + tumor_id + '/ctscan.npy'
    pan_path = data_path + '/' + tumor_id + '/pancreas.npy'

    pancreas = np.load(pan_path)
    pancreas = smoothing(pancreas)

    if tumor_id[:2] == 'PC' or tumor_id[:2] == 'PT':
        les_path = data_path + '/' + tumor_id + '/lesion.npy'
        lesion = np.load(les_path)
        lesion = smoothing(lesion)
    else:
        lesion = np.zeros(pancreas.shape)

    pancreas = morphology.dilation(pancreas, np.ones([3, 3, 1]))
    lesion = morphology.dilation(lesion, np.ones([3, 3, 1]))

    coords = masked_2D_sampler(lesion,
                               pancreas,
                               patch_size,
                               stride,
                               threshold,
                               max_amount=max_amount)

    img = np.load(img_path)
    img = windowing(img)
    img = minmax_normalization(img)
    if add_mask:
        mask = np.zeros(pancreas.shape)
        mask[np.where(lesion == 1)] = 1
        mask[np.where(pancreas == 1)] = 1
        img = img * mask

    for coord in coords:
        mask_pancreas = img[coord[1]:coord[4], coord[2]:coord[5], coord[3]]
        X.append(mask_pancreas)
        Y.append(coord[0])

    return X, Y