def count_proportion():
    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(
        pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]

    n_white = 0
    n_black = 0

    for k, p in enumerate(luna_data_paths):
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        img = data_transforms.hu2normHU(img)
        id = os.path.basename(p).replace('.mhd', '')
        print id

        annotations = id2zyxd[id]

        img_out, annotations_out = data_transforms.transform_scan3d(
            img,
            pixel_spacing=pixel_spacing,
            p_transform=config().p_transform,
            p_transform_augment=None,
            # config().p_transform_augment,
            luna_annotations=annotations,
            luna_origin=origin)

        mask = data_transforms.make_3d_mask_from_annotations(img_out.shape,
                                                             annotations_out,
                                                             shape='sphere')
        n_white += np.sum(mask)
        n_black += mask.shape[0] * mask.shape[1] * mask.shape[2] - np.sum(mask)

        print 'white', n_white
        print 'black', n_black
Пример #2
0
def test_luna3d_2():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = [
        '/mnt/sda3/data/kaggle-lung/luna_test_patient/1.3.6.1.4.1.14519.5.2.1.6279.6001.943403138251347598519939390311.mhd']

    for k, p in enumerate(luna_data_paths):
        id = os.path.basename(p).replace('.mhd', '')
        print id
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        lung_mask = lung_segmentation.segment_HU_scan(img)
        annotations = id2zyxd[id]
        x, annotations_tf, tf_matrix, lung_mask_out = data_transforms.transform_scan3d(data=img,
                                                                                       pixel_spacing=pixel_spacing,
                                                                                       p_transform=p_transform,
                                                                                       luna_annotations=annotations,
                                                                                       p_transform_augment=None,
                                                                                       luna_origin=origin,
                                                                                       lung_mask=lung_mask,
                                                                                       world_coord_system=True)

        y = data_transforms.make_3d_mask_from_annotations(img_shape=x.shape, annotations=annotations_tf, shape='sphere')

        for zyxd in annotations_tf:
            plot_slice_3d_3(x, lung_mask_out, y, 0, id, idx=zyxd)
            plot_slice_3d_3(x, lung_mask_out, y, 1, id, idx=zyxd)
            plot_slice_3d_3(x, lung_mask_out, y, 2, id, idx=zyxd)
Пример #3
0
def test_luna3d():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]

    # luna_data_paths = [
    #     pathfinder.LUNA_DATA_PATH + '/1.3.6.1.4.1.14519.5.2.1.6279.6001.287966244644280690737019247886.mhd']

    luna_data_paths = [
        '/mnt/sda3/data/kaggle-lung/luna_test_patient/1.3.6.1.4.1.14519.5.2.1.6279.6001.943403138251347598519939390311.mhd']
    for k, p in enumerate(luna_data_paths):
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        id = os.path.basename(p).replace('.mhd', '')
        print id

        annotations = id2zyxd[id]

        img_out, mask, annotations_out = config().data_prep_function(img,
                                                                     pixel_spacing=pixel_spacing,
                                                                     luna_annotations=annotations,
                                                                     luna_origin=origin)

        mask[mask == 0.] = 0.1
        print annotations_out
        for zyxd in annotations_out:
            plot_slice_3d_2(img_out, mask, 0, id, idx=zyxd)
            plot_slice_3d_2(img_out, mask, 1, id, idx=zyxd)
            plot_slice_3d_2(img_out, mask, 2, id, idx=zyxd)
Пример #4
0
def test_luna3d():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]

    # luna_data_paths = [
    #     pathfinder.LUNA_DATA_PATH + '/1.3.6.1.4.1.14519.5.2.1.6279.6001.287966244644280690737019247886.mhd']

    luna_data_paths = [
        '/mnt/sda3/data/kaggle-lung/luna_test_patient/1.3.6.1.4.1.14519.5.2.1.6279.6001.943403138251347598519939390311.mhd']
    for k, p in enumerate(luna_data_paths):
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        id = os.path.basename(p).replace('.mhd', '')
        print(id)

        annotations = id2zyxd[id]

        img_out, mask, annotations_out = config().data_prep_function(img,
                                                                     pixel_spacing=pixel_spacing,
                                                                     luna_annotations=annotations,
                                                                     luna_origin=origin)

        mask[mask == 0.] = 0.1
        print(annotations_out)
        for zyxd in annotations_out:
            plot_slice_3d_2(img_out, mask, 0, id, idx=zyxd)
            plot_slice_3d_2(img_out, mask, 1, id, idx=zyxd)
            plot_slice_3d_2(img_out, mask, 2, id, idx=zyxd)
Пример #5
0
def test_luna_patches_3d():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]

    # pid = '1.3.6.1.4.1.14519.5.2.1.6279.6001.138080888843357047811238713686'
    # luna_data_paths = [pathfinder.LUNA_DATA_PATH + '/%s.mhd' % pid]
    for k, p in enumerate(luna_data_paths):
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        # img = data_transforms.hu2normHU(img)
        id = os.path.basename(p).replace('.mhd', '')
        print id

        annotations = id2zyxd[id]
        print annotations
        for zyxd in annotations:
            img_out, mask = config().data_prep_function_train(img,
                                                              pixel_spacing=pixel_spacing,
                                                              p_transform=config().p_transform,
                                                              p_transform_augment=config().p_transform_augment,
                                                              patch_center=zyxd,
                                                              luna_annotations=annotations,
                                                              luna_origin=origin)
            try:
                plot_slice_3d_2(img_out, mask, 0, id)
                plot_slice_3d_2(img_out, mask, 1, id)
                plot_slice_3d_2(img_out, mask, 2, id)
            except:
                pass
        print '------------------------------------------'
Пример #6
0
def count_proportion():
    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]

    n_white = 0
    n_black = 0

    for k, p in enumerate(luna_data_paths):
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        img = data_transforms.hu2normHU(img)
        id = os.path.basename(p).replace('.mhd', '')
        print id

        annotations = id2zyxd[id]

        img_out, annotations_out = data_transforms.transform_scan3d(img,
                                                                    pixel_spacing=pixel_spacing,
                                                                    p_transform=config().p_transform,
                                                                    p_transform_augment=None,
                                                                    # config().p_transform_augment,
                                                                    luna_annotations=annotations,
                                                                    luna_origin=origin)

        mask = data_transforms.make_3d_mask_from_annotations(img_out.shape, annotations_out, shape='sphere')
        n_white += np.sum(mask)
        n_black += mask.shape[0] * mask.shape[1] * mask.shape[2] - np.sum(mask)

        print 'white', n_white
        print 'black', n_black
Пример #7
0
def test_luna3d():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = [
        '/mnt/sda3/data/kaggle-lung/luna_test_patient/1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474.mhd'
    ]

    candidates = utils.load_pkl(
        '/mnt/sda3/data/kaggle-lung/luna_test_patient/1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474.pkl'
    )

    candidates = candidates[:4]
    print(candidates)
    print('--------------')
    print(id2zyxd[
        '1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474'])

    for k, p in enumerate(luna_data_paths):
        id = os.path.basename(p).replace('.mhd', '')
        print(id)
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        lung_mask = lung_segmentation.segment_HU_scan_ira(img)
        print(np.min(lung_mask), np.max(lung_mask))
        x, annotations_tf, tf_matrix, lung_mask_out = data_transforms.transform_scan3d(
            data=img,
            pixel_spacing=pixel_spacing,
            p_transform=p_transform,
            luna_annotations=candidates,
            p_transform_augment=None,
            luna_origin=origin,
            lung_mask=lung_mask,
            world_coord_system=False)

        print(np.min(lung_mask_out), np.max(lung_mask_out))

        plot_slice_3d_2(x, lung_mask_out, 0, id)
        plot_slice_3d_2(x, lung_mask_out, 1, id)
        plot_slice_3d_2(x, lung_mask_out, 2, id)

        # for zyxd in annotations_tf:
        #     plot_slice_3d_2(x, lung_mask_out, 0, id, idx=zyxd)
        #     plot_slice_3d_2(x, lung_mask_out, 1, id, idx=zyxd)
        #     plot_slice_3d_2(x, lung_mask_out, 2, id, idx=zyxd)

        for i in range(136, x.shape[1]):
            plot_slice_3d_2(x,
                            lung_mask_out,
                            1,
                            str(id) + str(i),
                            idx=np.array([200, i, 200]))
Пример #8
0
def test_luna3d():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = [
        '/mnt/sda3/data/kaggle-lung/luna_test_patient/1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474.mhd']

    candidates = utils.load_pkl(
        '/mnt/sda3/data/kaggle-lung/luna_test_patient/1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474.pkl')

    candidates = candidates[:4]
    print candidates
    print '--------------'
    print id2zyxd['1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474']

    for k, p in enumerate(luna_data_paths):
        id = os.path.basename(p).replace('.mhd', '')
        print id
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        lung_mask = lung_segmentation.segment_HU_scan_ira(img)
        print np.min(lung_mask), np.max(lung_mask)
        x, annotations_tf, tf_matrix, lung_mask_out = data_transforms.transform_scan3d(data=img,
                                                                                       pixel_spacing=pixel_spacing,
                                                                                       p_transform=p_transform,
                                                                                       luna_annotations=candidates,
                                                                                       p_transform_augment=None,
                                                                                       luna_origin=origin,
                                                                                       lung_mask=lung_mask,
                                                                                       world_coord_system=False)

        print np.min(lung_mask_out), np.max(lung_mask_out)

        plot_slice_3d_2(x, lung_mask_out, 0, id)
        plot_slice_3d_2(x, lung_mask_out, 1, id)
        plot_slice_3d_2(x, lung_mask_out, 2, id)

        # for zyxd in annotations_tf:
        #     plot_slice_3d_2(x, lung_mask_out, 0, id, idx=zyxd)
        #     plot_slice_3d_2(x, lung_mask_out, 1, id, idx=zyxd)
        #     plot_slice_3d_2(x, lung_mask_out, 2, id, idx=zyxd)

        for i in xrange(136, x.shape[1]):
            plot_slice_3d_2(x, lung_mask_out, 1, str(id) + str(i), idx=np.array([200, i, 200]))
def test1():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(
        pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]
    print len(luna_data_paths)
    print id2zyxd.keys()

    for k, p in enumerate(luna_data_paths):
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        img = data_transforms.hu2normHU(img)
        id = os.path.basename(p).replace('.mhd', '')

        for nodule_zyxd in id2zyxd.itervalues():
            zyx = np.array(nodule_zyxd[:3])
            voxel_coords = utils_lung.world2voxel(zyx, origin, pixel_spacing)
            diameter_mm = nodule_zyxd[-1]
            radius_px = diameter_mm / pixel_spacing[1] / 2.
            roi_radius = (radius_px, radius_px)
            slice = img[voxel_coords[0], :, :]
            slice_prev = img[voxel_coords[0] - 1, :, :]
            slice_next = img[voxel_coords[0] + 1, :, :]
            roi_center_yx = (voxel_coords[1], voxel_coords[2])
            mask = data_transforms.make_2d_mask(slice.shape,
                                                roi_center_yx,
                                                roi_radius,
                                                masked_value=0.1)
            plot_2d(slice, mask, id, image_dir)

            plot_2d_4(slice, slice_prev, slice_next, mask, id, image_dir)

            a = [{'center': roi_center_yx, 'diameter_mm': diameter_mm}]
            p_transform = {
                'patch_size': (256, 256),
                'mm_patch_size': (360, 360)
            }
            slice_patch, mask_patch = data_transforms.luna_transform_slice(
                slice, a, pixel_spacing[1:], p_transform, None)
            plot_2d(slice_patch, mask_patch, id, image_dir)
def test1():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    # sys.stdout = logger.Logger(image_dir + '/test_luna.log')
    # sys.stderr = sys.stdout

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(
        pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]
    print len(luna_data_paths)
    print id2zyxd.keys()

    for k, p in enumerate(luna_data_paths):
        img, origin, spacing = utils_lung.read_mhd(p)
        img = data_transforms.hu2normHU(img)
        id = os.path.basename(p).replace('.mhd', '')
        for roi in id2zyxd[id]:
            zyx = np.array(roi[:3])
            voxel_coords = utils_lung.world2voxel(zyx, origin, spacing)
            print spacing
            radius_mm = roi[-1] / 2.
            radius_px = radius_mm / spacing[1]
            print 'r in pixels =', radius_px
            # roi_radius = (32.5, 32.5)
            roi_radius = (radius_px, radius_px)
            slice = img[voxel_coords[0], :, :]
            roi_center_yx = (voxel_coords[1], voxel_coords[2])
            # print slice.shape, slice_resample.shape
            mask = make_circular_mask(slice.shape, roi_center_yx, roi_radius)
            plot_2d(slice, mask, id, image_dir)

            slice_mm, _ = resample(slice, spacing[1:])
            roi_center_mm = tuple(
                int(r * ps) for r, ps in zip(roi_center_yx, spacing[1:]))
            mask_mm = make_circular_mask(slice_mm.shape, roi_center_mm,
                                         (radius_mm, radius_mm))
            plot_2d(slice_mm, mask_mm, id, image_dir)
def test_luna3d():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = [
        'problem_patients/1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474.mhd'
    ]

    candidates = utils.load_pkl(
        'problem_patients/1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474.pkl'
    )

    candidates = candidates[:4]
    print candidates
    print '--------------'
    print id2zyxd[
        '1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474']

    for k, p in enumerate(luna_data_paths):
        id = os.path.basename(p).replace('.mhd', '')
        print id
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        lung_mask = lung_segmentation.segment_HU_scan_elias(img)
        x, annotations_tf, tf_matrix, lung_mask_out = data_transforms.transform_scan3d(
            data=img,
            pixel_spacing=pixel_spacing,
            p_transform=p_transform,
            luna_annotations=candidates,
            p_transform_augment=None,
            luna_origin=origin,
            lung_mask=lung_mask,
            world_coord_system=False)

        for zyxd in annotations_tf:
            plot_slice_3d_2(x, lung_mask_out, 0, id, img_dir='./', idx=zyxd)
            plot_slice_3d_2(x, lung_mask_out, 1, id, img_dir='./', idx=zyxd)
            plot_slice_3d_2(x, lung_mask_out, 2, id, img_dir='./', idx=zyxd)
Пример #12
0
def test1():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    # sys.stdout = logger.Logger(image_dir + '/test_luna.log')
    # sys.stderr = sys.stdout

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]
    print len(luna_data_paths)
    print id2zyxd.keys()

    for k, p in enumerate(luna_data_paths):
        img, origin, spacing = utils_lung.read_mhd(p)
        img = data_transforms.hu2normHU(img)
        id = os.path.basename(p).replace('.mhd', '')
        for roi in id2zyxd[id]:
            zyx = np.array(roi[:3])
            voxel_coords = utils_lung.world2voxel(zyx, origin, spacing)
            print spacing
            radius_mm = roi[-1] / 2.
            radius_px = radius_mm / spacing[1]
            print 'r in pixels =', radius_px
            # roi_radius = (32.5, 32.5)
            roi_radius = (radius_px, radius_px)
            slice = img[voxel_coords[0], :, :]
            roi_center_yx = (voxel_coords[1], voxel_coords[2])
            # print slice.shape, slice_resample.shape
            mask = make_circular_mask(slice.shape, roi_center_yx, roi_radius)
            plot_2d(slice, mask, id, image_dir)

            slice_mm, _ = resample(slice, spacing[1:])
            roi_center_mm = tuple(int(r * ps) for r, ps in zip(roi_center_yx, spacing[1:]))
            mask_mm = make_circular_mask(slice_mm.shape, roi_center_mm, (radius_mm, radius_mm))
            plot_2d(slice_mm, mask_mm, id, image_dir)
Пример #13
0
def test1():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]
    print len(luna_data_paths)
    print id2zyxd.keys()

    for k, p in enumerate(luna_data_paths):
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        img = data_transforms.hu2normHU(img)
        id = os.path.basename(p).replace('.mhd', '')

        for nodule_zyxd in id2zyxd.itervalues():
            zyx = np.array(nodule_zyxd[:3])
            voxel_coords = utils_lung.world2voxel(zyx, origin, pixel_spacing)
            diameter_mm = nodule_zyxd[-1]
            radius_px = diameter_mm / pixel_spacing[1] / 2.
            roi_radius = (radius_px, radius_px)
            slice = img[voxel_coords[0], :, :]
            slice_prev = img[voxel_coords[0] - 1, :, :]
            slice_next = img[voxel_coords[0] + 1, :, :]
            roi_center_yx = (voxel_coords[1], voxel_coords[2])
            mask = data_transforms.make_2d_mask(slice.shape, roi_center_yx, roi_radius, masked_value=0.1)
            plot_2d(slice, mask, id, image_dir)

            plot_2d_4(slice, slice_prev, slice_next, mask, id, image_dir)

            a = [{'center': roi_center_yx, 'diameter_mm': diameter_mm}]
            p_transform = {'patch_size': (256, 256),
                           'mm_patch_size': (360, 360)}
            slice_patch, mask_patch = data_transforms.luna_transform_slice(slice, a, pixel_spacing[1:],
                                                                           p_transform, None)
            plot_2d(slice_patch, mask_patch, id, image_dir)
Пример #14
0
def test_luna_patches_3d():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = utils_lung.get_patient_data_paths(
        pathfinder.LUNA_DATA_PATH)
    luna_data_paths = [p for p in luna_data_paths if '.mhd' in p]

    # pid = '1.3.6.1.4.1.14519.5.2.1.6279.6001.138080888843357047811238713686'
    # luna_data_paths = [pathfinder.LUNA_DATA_PATH + '/%s.mhd' % pid]
    for k, p in enumerate(luna_data_paths):
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        # img = data_transforms.hu2normHU(img)
        id = os.path.basename(p).replace('.mhd', '')
        print(id)

        annotations = id2zyxd[id]
        print(annotations)
        for zyxd in annotations:
            img_out, mask = config().data_prep_function_train(
                img,
                pixel_spacing=pixel_spacing,
                p_transform=config().p_transform,
                p_transform_augment=config().p_transform_augment,
                patch_center=zyxd,
                luna_annotations=annotations,
                luna_origin=origin)
            try:
                plot_slice_3d_2(img_out, mask, 0, id)
                plot_slice_3d_2(img_out, mask, 1, id)
                plot_slice_3d_2(img_out, mask, 2, id)
            except:
                pass
        print('------------------------------------------')
Пример #15
0
def test_luna3d():
    image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH)
    image_dir = image_dir + '/test_luna/'
    utils.auto_make_dir(image_dir)

    id2zyxd = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

    luna_data_paths = [
        'problem_patients/1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474.mhd']

    candidates = utils.load_pkl(
        'problem_patients/1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474.pkl')

    candidates = candidates[:4]
    print candidates
    print '--------------'
    print id2zyxd['1.3.6.1.4.1.14519.5.2.1.6279.6001.877026508860018521147620598474']

    for k, p in enumerate(luna_data_paths):
        id = os.path.basename(p).replace('.mhd', '')
        print id
        img, origin, pixel_spacing = utils_lung.read_mhd(p)
        lung_mask = lung_segmentation.segment_HU_scan_elias(img)
        x, annotations_tf, tf_matrix, lung_mask_out = data_transforms.transform_scan3d(data=img,
                                                                                       pixel_spacing=pixel_spacing,
                                                                                       p_transform=p_transform,
                                                                                       luna_annotations=candidates,
                                                                                       p_transform_augment=None,
                                                                                       luna_origin=origin,
                                                                                       lung_mask=lung_mask,
                                                                                       world_coord_system=False)

        for zyxd in annotations_tf:
            plot_slice_3d_2(x, lung_mask_out, 0, id, img_dir='./', idx=zyxd)
            plot_slice_3d_2(x, lung_mask_out, 1, id, img_dir='./', idx=zyxd)
            plot_slice_3d_2(x, lung_mask_out, 2, id, img_dir='./', idx=zyxd)
Пример #16
0
if len(sys.argv) < 2:
    sys.exit("Usage: test_luna_scan.py <configuration_name>")

config_name = sys.argv[1]
set_configuration('configs_fpred_scan', config_name)

# predictions path
predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH)
outputs_path = predictions_dir + '/%s' % config_name
pid2candidates_path = utils_lung.get_candidates_paths(outputs_path)
pid2candidates = {}
for k, v in pid2candidates_path.iteritems():
    pid2candidates[k] = utils.load_pkl(v)

pid2annotations = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

n_top = 1
tp_top_n = 0
fp_top_n = 0
tp = 0
n_pos = 0
idx1 = []
for k in pid2candidates.iterkeys():
    print '----------------------------------------'
    print k
    n_true = len(pid2annotations[k])
    n_det_top = int(np.sum(pid2candidates[k][:n_top, 3]))
    n_fp_top = int(n_top - np.sum(pid2candidates[k][:n_top, 3]))
    n_det = int(np.sum(pid2candidates[k][:, 3]))
    i1 = np.where(pid2candidates[k][:n_top, 3] == 1)[0]
Пример #17
0
from configuration import set_configuration
import data_transforms

if len(sys.argv) < 2:
    sys.exit("Usage: evaluate_luna_scan.py <configuration_name>")

config_name = sys.argv[1]
set_configuration('configs_seg_scan', config_name)

predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH)
outputs_path = predictions_dir + '/%s' % config_name

blob_files = sorted(glob.glob(outputs_path + '/*.pkl'))
# print(blob_files)

pid2annotations = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH)

tp = 0
n_pos = 0
n_blobs = 0
for p in blob_files:
    pid = utils_lung.extract_pid_filename(p, '.pkl')
    blobs = utils.load_pkl(p)
    n_blobs += len(blobs)
    print(pid)
    print('n_blobs', len(blobs))
    print('tp / n pos ', int(np.sum(blobs[:, -1])), len(pid2annotations[pid]))
    if int(np.sum(blobs[:, -1])) < len(pid2annotations[pid]):
        print('-------- HERE!!!!!! ------------')
    tp += np.sum(blobs[:, -1])
    print('=====================================')