コード例 #1
0
def lung_slic_tool(filename):
    prename, extname = os.path.splitext(filename)
    pathname = os.path.split(filename)[0]

    if (extname == '.npy'):
        segresult = np.load(filename)
        labels = np.load(prename + '.label.npy')

    elif (extname == '.mhd'):
        npyname = filename + '.npy'
        filelist = [pathname + '/' + i for i in os.listdir(pathname)]
        if npyname in filelist:
            segresult = np.load(npyname)
            labels = np.load(filename + '.label.npy')
        else:
            full_image_info = sitk.ReadImage(filename)
            full_scan = sitk.GetArrayFromImage(full_image_info)
            old_spacing = np.array(full_image_info.GetSpacing())[::-1]
            image, new_spacing = mt.resample(full_scan, old_spacing)
            #####
            #image = image[195:200]
            #####
            print("slic segmenting")
            labels = lc.slic_segment(image, view_result=True)
            print("segmentation complete")
コード例 #2
0
		#mbb.z_top = 195
		#mbb.z_bottom = 205
		#mbb.y_top = 110
		#mbb.y_bottom = 120
		#mbb.x_top = 105
		#mbb.x_bottom = 115
		image_bounded = image[mbb.z_top:mbb.z_bottom+1, mbb.y_top:mbb.y_bottom+1, mbb.x_top:mbb.x_bottom+1]
		print('Lung Segmentation Done. time:{}s' .format(time.time()-start_time))

		#nodule_matrix, cindex = cd.candidate_detection(segimage)
		#cluster_labels = lc.seed_volume_cluster(nodule_matrix, cluster_size=30, result_vision=False)
		num_segments = int(image_bounded.shape[0] * image_bounded.shape[1] * image_bounded.shape[2] / 27)	#the volume of a 3mm nodule is 27 voxels
		#num_segments = 20
		print('cluster number:%d' %(num_segments))
		cluster_labels = 0 - np.ones(shape=image.shape, dtype=int)
		cluster_labels_bounded = lc.slic_segment(image_bounded, compactness=0.01, num_segments=num_segments)
		print('Clustering Done. time:{}s' .format(time.time()-start_time))
		cluster_labels[mbb.z_top:mbb.z_bottom+1, mbb.y_top:mbb.y_bottom+1, mbb.x_top:mbb.x_bottom+1] = cluster_labels_bounded
		cluster_labels[np.logical_or(segmask==0, image<-600)] = -1
		#cluster_labels_filtered_fast = lc.cluster_filter_fast(image, cluster_labels)
		#print('Cluster Filtering Fast Done. time:{}s'.format(time.time() - start_time))
		#cluster_labels_filtered = lc.cluster_filter(image, cluster_labels)	#the clusters with no tissue are filetered out
		#candidate_coords_slow, candidate_labels_slow = lc.cluster_centers_fast(cluster_labels_filtered)
		#volume_candidated = cvm.view_coordinations(image, candidate_coords_slow, window_size=10, reverse=False, slicewise=True, show=False)
		#np.save(vision_path+"/"+uid+"_candidate_slow.npy", volume_candidated)
		#print('candidate slow number:%d' %(len(candidate_coords_slow)))
		#print('Cluster Filtering Done. time:{}s'.format(time.time() - start_time))

		#segresultfast = lc.segment_vision(image, cluster_labels_filtered_fast)
		#np.save(vision_path+"/"+uid+"_segresultfast.npy", segresultfast)
		if RESULT_VISION: