def main(): if len(sys.argv) > 1: data_dir = sys.argv[1] # data_dir = '/hpc/bsha219/lung/Data/Human_PE_Study_HRC/ST12/TLC/Raw/DICOMS' patient_scans = load_scan( '/hpc/bsha219/lung/Data/Human_PE_Study_HRC/ST12/TLC/Raw/DICOMS') patient_images = get_pixels_hu(patient_scans) global artery_mask artery_mask = [] for k in range(115, 215): global coords coords = [] img = patient_images[k] root = tk.Tk() im = Image.fromarray(img) photo = ImageTk.PhotoImage(im) canvas = tk.Canvas(root, width=512, height=512) canvas.pack() canvas.create_image(256, 256, image=photo) canvas.bind("<Button-1>", onclick) root.mainloop() for i in range(img.shape[0]): for j in range(img.shape[0]): if img[i][j] > 0: img[i][j] *= 12 # blurred_f = ndimage.gaussian_filter(img, sigma=3) filter_blurred_f = filters.median_filter(img, 3) filter_blurred_f2 = ndimage.gaussian_filter(filter_blurred_f, sigma=1) alpha = 12 sharpened = filter_blurred_f + alpha * (filter_blurred_f - filter_blurred_f2) seed = np.zeros(img.shape) for jj in range(len(coords)): seed[int(coords[jj][1]), int(coords[jj][0])] = 1 seg, phi, its = lvlset(sharpened, seed, max_its=1000, display=True, alpha=0.4) segment = seg * 1.0 # scipy.misc.imsave('/hpc/bsha219/Python/Behdad/Out_arterial_mask/LungMask%.4d.jpg' % k, segment) # binary files matplotlib.image.imsave( '/hpc/bsha219/Python/Behdad/Out_arterial_mask/' + str(k) + '.png', segment) # RGB files
def main(): if len(sys.argv) > 1: data_dir = sys.argv[1] # data_dir = '/hpc/bsha219/lung/Data/ST12/Raw/DICOMS' # data_dir = '/hpc/bsha219/lung/Data/P2BRP257-H12076/FRC/Raw/DICOMS' patient_scans = load_scan('/hpc/bsha219/lung/Data/Human_PE_Study_HRC/ST12/TLC/Raw/DICOMS') patient_images = get_pixels_hu(patient_scans) # imgs, spacing = downsample(patient_images, patient_scans, [1, 1, 1]) # segmented = [] for i in range(len(patient_images)): lungs, left_lung, right_lung = lung_segment(patient_images[i]) # segmented.append(lungs) # segmented = np.asarray(segmented) lungs = np.uint8(lungs) # to save them as a stack of masks in a directory binary_im = Image.fromarray(lungs) binary_im.save('/hpc/bsha219/Python/Behdad/Lung_masks/LungMask%.4d.jpg' % i, quality=100)
from load_scan import load_scan, get_pixels_hu from Lung_Segmentation import lung_segment, generate_markers import scipy.ndimage as ndimage import matplotlib.pyplot as plt import matplotlib.image as im ct_images = load_scan('../examples/sample_inputs') images_hu = get_pixels_hu(ct_images) for i in range(len(images_hu)): marker_internal, marker_watershed = generate_markers(images_hu[i]) marker_internal[marker_internal == 2] = 1 lungs, lung_left, lung_right = lung_segment(images_hu[i]) lungs[lungs == 17] = 1 lungs[lungs == 5] = 1 ex = lungs - marker_internal * 1.0 vessel = ndimage.binary_opening(ex) plt.imshow(vessel) plt.show() im.imsave('./results/Vessel' + str(i + 1) + '.jpg', vessel)
from load_scan import load_scan, get_pixels_hu from Lung_Segmentation import lung_segment, generate_markers import scipy.ndimage as ndimage import matplotlib import matplotlib.pyplot as plt patient_scans = load_scan('/hpc/bsha219/lung/Data/ST12/Raw/DICOMS') patient_images = get_pixels_hu(patient_scans) for i in range(len(patient_images)): marker_internal, marker_external, marker_watershed, left_lung, right_lung, ex_left, ex_right, watershed_left, watershed_right = generate_markers( patient_images[i]) seg, watershed, mark_int, mark_ext, mark_watershed, wat_left, wat_right = lung_segment( patient_images[i]) watershed[watershed == 128] = 0 watershed[watershed == 255] = 1 ex = watershed - marker_internal * 1.0 vessel = ndimage.binary_opening(ex) # matplotlib.image.imsave('/hpc/bsha219/Python/Behdad/Inside_vessels/' + str(i) + '.png', vessel) # plt.imshow(vessel, cmap='gray') # plt.show()