Exemple #1
0
def cases_scans_lesions(mode, samplelist, thresholds=None):
    """Iterate (case_id, scan_id, lesions)."""
    mode = ImageMode(mode)
    path = dwi.paths.samplelist_path(mode, samplelist)
    patients = dwi.files.read_patients_file(path)
    dwi.patient.label_lesions(patients, thresholds=thresholds)
    return ((p.num, s, p.lesions) for p in patients for s in p.scans)
Exemple #2
0
def main():
    mode = ImageMode('DWI-Mono-ADCm')
    paths = dwi.paths.Paths(mode)
    cases = read_cases()
    cases = cases[:5]
    it = product(cases, [1, 2], 'ab')
    it = ((c, '{}{}'.format(r, s)) for c, r, s in it)
    # for case, _scan1, _scan2 in it:
    #     scan = '{}{}'.format(_scan1, _scan2)
    #     get_image_stats(paths, case, scan)
    it = (get_image_stats(paths, c, s) for c, s in it)
    it = filter(None, it)
    d = dict(headers='keys', tablefmt='tsv', floatfmt='1.5f', missingval='-')
    s = tabulate(it, **d)
    s = s.replace('\t', ', ')
    print(s)
Exemple #3
0
def main():
    modes = ['DWI-Mono-ADCm', 'DWI-Kurt-ADCk', 'DWI-Kurt-K']
    modes = [ImageMode(x) for x in modes]
    samplelist = 'bothscansonly'
    logging.basicConfig(level=LOGLEVEL)
    process_all(modes, samplelist)
Exemple #4
0
              ],
          help='imaging modes')
    p.add('-s', '--samplelist', default='all',
          help='samplelist identifier')
    p.add('-c', '--cases', nargs='+', type=int,
          help='cases to include, if not all')
    return p.parse_args()


def read_case(mode, case, scan, lesions):
    """Read case. Return raw DWI, pmap, pmask, lmasks, initial prostate slice
    index.
    """
    img = dwi.dataset.read_tmap(mode, case, scan)[:, :, :, 0]
    img = dwi.util.normalize(img, mode)
    rawmode = ImageMode('DWI-b2000')
    raw = dwi.dataset.read_tmap(rawmode[0], case, scan,
                                params=[-1])[:, :, :, 0]
    raw = dwi.util.normalize(raw, rawmode)
    pmask = dwi.dataset.read_prostate_mask(mode, case, scan)
    lmasks = [dwi.dataset.read_lesion_mask(mode, case, scan, x) for x in
              lesions]

    mbb = img.mbb()
    img = img[mbb]
    raw = raw[mbb]
    pmask = pmask[mbb]
    lmasks = [x[mbb] for x in lmasks]

    prostate_slices = pmask.mbb(pad=(0, np.inf, np.inf))
    img = img[prostate_slices]
Exemple #5
0
    # centroids = [int(round(dwi.util.centroid(x)[0])) for x in masks]
    # centroid = int(round(dwi.util.centroid(mask)[0]))

    logging.debug('Lesion centroids (total): %s (%s)', centroids, centroid)
    logging.info('Mask shape: %s, centroid: %i, slice: %s', mask.shape,
                 centroid, slice_index)
    if slice_index is None:
        slice_index = centroid
    mask = mask[slice_index]

    return mask, slice_index


def read_lmask(mode, case, scan):
    mode = ImageMode(mode)
    paths = []
    try:
        for i in range(1, 4):
            path = Path(
                dwi.paths.mask_path(mode, 'lesion', case, scan, lesion=i))
            if path.exists():
                paths.append(path)
    except IOError:
        pass
    masks = [dwi.files.read_mask(x) for x in paths]

    # # Manually override slice index.
    # slice_indices = {
    #     (64, '1a', 'T2w-std'): 7,
    #     (64, '1a', 'T2-fitted'): 5,
Exemple #6
0
    # centroids = [int(round(dwi.util.centroid(x)[0])) for x in masks]
    # centroid = int(round(dwi.util.centroid(mask)[0]))

    logging.debug('Lesion centroids (total): %s (%s)', centroids, centroid)
    logging.info('Mask shape: %s, centroid: %i, slice: %s', mask.shape,
                 centroid, slice_index)
    if slice_index is None:
        slice_index = centroid
    mask = mask[slice_index]

    return mask, slice_index


def read_lmask(mode, case, scan):
    mode = ImageMode(mode)
    paths = []
    try:
        for i in range(1, 4):
            paths.append(dwi.paths.mask_path(mode, 'lesion', case, scan, i))
    except IOError:
        pass
    masks = [dwi.files.read_mask(x) for x in paths]

    # Manually override slice index.
    slice_indices = {
        (64, '1a', 'T2w-std'): 7,
        (64, '1a', 'T2-fitted'): 5,
        }

    slice_index = slice_indices.get((case, scan, str(mode)))