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]))
def data_prep_function(data, luna_annotations, pixel_spacing, luna_origin, p_transform=p_transform, p_transform_augment=None): # make sure the data is processed the same way lung_mask = lung_segmentation.segment_HU_scan_ira(data) x, annotations_tf, tf_matrix, lung_mask_out = data_transforms.transform_scan3d(data=data, pixel_spacing=pixel_spacing, p_transform=p_transform, luna_annotations=luna_annotations, p_transform_augment=None, luna_origin=luna_origin, lung_mask=lung_mask) x = data_transforms.pixelnormHU(x) y = data_transforms.make_3d_mask_from_annotations(img_shape=x.shape, annotations=annotations_tf, shape='sphere') return x, y, lung_mask_out, annotations_tf, tf_matrix
def data_prep_function(data, luna_annotations, pixel_spacing, luna_origin, p_transform=p_transform, p_transform_augment=None): # make sure the data is processed the same way lung_mask = lung_segmentation.segment_HU_scan_ira(data) annotatations_out = [] for zyxd in luna_annotations: zyx = np.array(zyxd[:3]) voxel_coords = utils_lung.world2voxel(zyx, luna_origin, pixel_spacing) zyxd_out = np.rint(np.append(voxel_coords, zyxd[-1])) annotatations_out.append(zyxd_out) annotatations_out = np.asarray(annotatations_out) return lung_mask, lung_mask, lung_mask, annotatations_out, None
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 test_dsb(): image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH) image_dir = image_dir + '/test_1/' utils.auto_make_dir(image_dir) patient_data_paths = utils_lung.get_patient_data_paths(pathfinder.DATA_PATH) print(len(patient_data_paths)) patient_data_paths = [pathfinder.DATA_PATH + '/01de8323fa065a8963533c4a86f2f6c1'] for k, p in enumerate(patient_data_paths): pid = utils_lung.extract_pid_dir(p) # sid2data, sid2metadata = utils_lung.get_patient_data(p) # sids_sorted = utils_lung.sort_sids_by_position(sid2metadata) # sids_sorted_jonas = utils_lung.sort_slices_jonas(sid2metadata) # sid2position = utils_lung.slice_location_finder(sid2metadata) # # jonas_slicethick = [] # for i in range(len(sids_sorted_jonas) - 1): # s = np.abs(sid2position[sids_sorted_jonas[i + 1]] - sid2position[sids_sorted_jonas[i]]) # jonas_slicethick.append(s) # # img = np.stack([data_transforms.ct2HU(sid2data[sid], sid2metadata[sid]) for sid in sids_sorted]) # xx = (jonas_slicethick[0], # sid2metadata[sids_sorted[0]]['PixelSpacing'][0], # sid2metadata[sids_sorted[0]]['PixelSpacing'][1]) # pixel_spacing = np.asarray(xx) img, pixel_spacing = utils_lung.read_dicom_scan(p) mask = lung_segmentation.segment_HU_scan_ira(img) print(pid) print(pixel_spacing) print('====================================') img_out, transform_matrix, mask_out = data_transforms.transform_scan3d(img, pixel_spacing=pixel_spacing, p_transform=config().p_transform, p_transform_augment=None, lung_mask=mask) for i in range(100, img_out.shape[0], 5): plot_slice_3d_2(img_out, mask_out, 0, str(pid) + str(i), idx=np.array([i, 200, 200])) plot_slice_3d_2(img_out, mask_out, 0, pid, idx=np.array(img_out.shape) / 2) plot_slice_3d_2(mask_out, img_out, 0, pid, idx=np.array(img_out.shape) / 4) plot_slice_3d_2(mask_out, img_out, 0, pid, idx=np.array(img_out.shape) / 8)
def test_dsb(): image_dir = utils.get_dir_path('analysis', pathfinder.METADATA_PATH) image_dir = image_dir + '/test_1/' utils.auto_make_dir(image_dir) patient_data_paths = utils_lung.get_patient_data_paths(pathfinder.DATA_PATH) print len(patient_data_paths) patient_data_paths = [pathfinder.DATA_PATH + '/01de8323fa065a8963533c4a86f2f6c1'] for k, p in enumerate(patient_data_paths): pid = utils_lung.extract_pid_dir(p) # sid2data, sid2metadata = utils_lung.get_patient_data(p) # sids_sorted = utils_lung.sort_sids_by_position(sid2metadata) # sids_sorted_jonas = utils_lung.sort_slices_jonas(sid2metadata) # sid2position = utils_lung.slice_location_finder(sid2metadata) # # jonas_slicethick = [] # for i in xrange(len(sids_sorted_jonas) - 1): # s = np.abs(sid2position[sids_sorted_jonas[i + 1]] - sid2position[sids_sorted_jonas[i]]) # jonas_slicethick.append(s) # # img = np.stack([data_transforms.ct2HU(sid2data[sid], sid2metadata[sid]) for sid in sids_sorted]) # xx = (jonas_slicethick[0], # sid2metadata[sids_sorted[0]]['PixelSpacing'][0], # sid2metadata[sids_sorted[0]]['PixelSpacing'][1]) # pixel_spacing = np.asarray(xx) img, pixel_spacing = utils_lung.read_dicom_scan(p) mask = lung_segmentation.segment_HU_scan_ira(img) print pid print pixel_spacing print '====================================' img_out, transform_matrix, mask_out = data_transforms.transform_scan3d(img, pixel_spacing=pixel_spacing, p_transform=config().p_transform, p_transform_augment=None, lung_mask=mask) for i in xrange(100, img_out.shape[0], 5): plot_slice_3d_2(img_out, mask_out, 0, str(pid) + str(i), idx=np.array([i, 200, 200])) plot_slice_3d_2(img_out, mask_out, 0, pid, idx=np.array(img_out.shape) / 2) plot_slice_3d_2(mask_out, img_out, 0, pid, idx=np.array(img_out.shape) / 4) plot_slice_3d_2(mask_out, img_out, 0, pid, idx=np.array(img_out.shape) / 8)