def hard_thresholding( self, proba, smoothing=None ): #print "MAX proba:",proba.max(), self.name res = proba > 0.5 res = irtk.largest_connected_component(res,fill_holes=False) if smoothing is None: return res else: return res.gaussianBlurring( sigma=smoothing ) >= 0.5
def soft_thresholding( self, proba ): res = proba > 0.5 res = irtk.largest_connected_component(res,fill_holes=False) proba[res==0] = 0 return proba
max(0,x_min-args.narrow_band-1):min(seg.shape[2],x_max+args.narrow_band+1+1)] tmp_img = img[max(0,z_min-args.narrow_band-1):min(img.shape[0],z_max+args.narrow_band+1+1), max(0,y_min-args.narrow_band-1):min(img.shape[1],y_max+args.narrow_band+1+1), max(0,x_min-args.narrow_band-1):min(img.shape[2],x_max+args.narrow_band+1+1)] background = (nd.binary_dilation( tmp_seg>0, structure=morphology.ball(args.narrow_band) ) == 0).astype('int32') if args.thorax: tmp_seg[background>0] = 4 else: tmp_seg[background>0] = 5 if args.debug: debug_seg = tmp_seg.transform(target=img,interpolation='nearest') debug_seg[irtk.largest_connected_component(debug_seg==0)>0] = debug_seg.max() irtk.imwrite("debug_seg.nii.gz",debug_seg) irtk.imwrite("debug_background.nii.gz",debug_seg!=5) tmp_img = tmp_img.rescale(-1,1) labels = random_walker( tmp_img.view(np.ndarray), tmp_seg.view(np.ndarray), beta=1000, mode='cg_mg', return_full_prob=False ) header = tmp_img.get_header() #header['dim'][3] = 5 if args.thorax: labels[labels==4] = 0