def load_image(img_name, centers): ''' loads a single image and returns a list of subimages (cubes around nodule-like findings) img_name: valid path to an image from current working directory centers: a list of the centroids of nodule-like occurrences in img in world coordinates ''' scan, spacing, origin, transfmat = readMhd(img_name) transfmat_toimg, _ = getImgWorldTransfMats(spacing, transfmat) # just need image centers = [convertToImgCoord(c, origin, transfmat_toimg) for c in centers] subimages = [extractCube(scan, spacing, c) for c in centers] return subimages
vol = float(n[header.index('Volume')]) if nodEqDiam(vol)>3: #only get nodule cubes for nodules>3mm ctr = np.array([float(n[header.index('x')]), float(n[header.index('y')]), float(n[header.index('z')])]) lnd = int(n[header.index('LNDbID')]) rad = int(n[header.index('RadID')]) # rads = list(map(int,list(n[header.index('RadID')].split(',')))) # radfindings = list(map(int,list(n[header.index('RadFindingID')].split(',')))) finding = int(n[header.index('FindingID')]) # print(lnd,finding,rads,radfindings) print(lnd,finding,rad,finding) # Read scan if lnd!=lndloaded: [scan,spacing,origin,transfmat] = readMhd('/media/tungthanhlee/SSD/grand_challenge/dataset/LNDB_segmentation/data/LNDb-{:04}.mhd'.format(lnd)) transfmat_toimg,transfmat_toworld = getImgWorldTransfMats(spacing,transfmat) lndloaded = lnd # Convert coordinates to image ctr = convertToImgCoord(ctr,origin,transfmat_toimg) # for rad,radfinding in zip(rads,radfindings): # Read segmentation mask [mask,_,_,_] = readMhd('/media/tungthanhlee/SSD/grand_challenge/dataset/LNDB_segmentation/masks/LNDb-{:04}_rad{}.mhd'.format(lnd,rad)) # Extract cube around nodule scan_cube = extractCube(scan,spacing,ctr) masknod = copy.copy(mask) # masknod[masknod!=radfinding] = 0 masknod[masknod!=finding] = 0
# ## 3 adjacent grayscale axial slides if not os.path.isdir('sliceTs'): os.mkdir('sliceTs') tsFiles = [] t_wlds = [] origins = [] id_c = 1 id_n = 0 input_shapes = [] for index in tqdm(range(len(filepaths_imgs))): sc, sp, o, t = utils.readMhd(filepaths_imgs[index]) t_img, t_wld = utils.getImgWorldTransfMats(sp, t) z_max = sc.shape[0] z_max_idx = z_max - (sc.shape[0] % 3) for id_n in range(int(z_max_idx * .6), int(z_max_idx * .9), 3): origins.append(o) input_shapes.append(sc.shape) slide = sc[int(id_n) - 1:int(id_n) + 2, :, :] slide = equalize_hist(slide) slide = anisotropic_diffusion(slide, voxelspacing=sp, kappa=20, gamma=0.01, niter=100, option=2)