# Compute error err[2, n, r] = np.mean(Y_h[M] != Y[M]) dcc[2, n, r] = dice(Y_h[M], Y[M]) if vis: fn_segs = fn + 'SGM_segs_p' + str(n + 1) + '_r' + str(r + 1) + '.png' plot_segmentation(Y_h, savefn=fn_segs) ''' Unsupervised hidden Potts''' # Initialize model UHP = VariationalHiddenPotts(num_components=K, num_channels=D, max_iter=max_iter, tol=x_tol, init_params='kmeans', tissue_specific=True) # Segment image Y_h, post, theta = UHP.segment(X, beta=beta) # Set cluster assignments to correct tissue labels Y_h = set_classes(Y_h, z) # Compute error err[3, n, r] = np.mean(Y_h[M] != Y[M]) dcc[3, n, r] = dice(Y_h[M], Y[M]) # Plot images, plus error image if vis:
scan[scan < 0] = 0 scan[scan > 255] = 255 scan = scan / 255. # Load segmentation segm = np.fromfile(pdir + '.raw', count=H * W, dtype='uint8') # Reshape binary list to image segm = nd.rotate(segm.reshape((H, W)), 90) # Restrict segmentation for k in np.setdiff1d(np.unique(segm), np.arange(K)): segm[segm == k] = 0 hPotts = VariationalHiddenPotts(num_components=K, num_channels=D, tissue_specific=True) Y1 = hPotts.one_hot(segm) # Strip skull scan[segm == 0] = 0 for d in range(3): X[n, :, :, d] = scan Y[n, :, :, :] = Y1 if os.path.exists('beta_brainweb01.npy'): # Load previously estimated smoothing parameters beta_h = np.load('beta_brainweb01.npy')