# Choose labels ix = rnd.choice(np.arange(Yk.shape[0]), size=1, p=Wk / np.sum(Wk)) # One-hot label image y[Yk[ix, 0], Yk[ix, 1], k] = True z[k, :] = np.array([Yk[ix, 0], Yk[ix, 1], k]) if vis: fn_segs = fn + 'TRUE_scan_p' + str(n + 1) + '_r' + str(r + 1) + '.png' plot_scan(X[:, :, 0], savefn=fn_segs) fn_segs = fn + 'TRUE_segs_p' + str(n + 1) + '_r' + str(r + 1) + '.png' plot_segmentation(Y, savefn=fn_segs) # Shape of X H, W, D = X.shape '''Scikit's VB GMM''' # # Initialize model # model = BayesianGaussianMixture(n_components=K, # max_iter=max_iter, # verbose=3) # # Fit model # model.fit(X.reshape((-1, 1))) # # Segment image # Y_h = model.predict(X.reshape((-1, 1))).reshape((H, W))
# Choose labels ix = rnd.choice(np.arange(Yk.shape[0]), size=1, p=Wk / np.sum(Wk)) # One-hot label image y[Yk[ix, 0], Yk[ix, 1], k] = True z[k, :] = np.array([Yk[ix, 0], Yk[ix, 1], k]) if vis: fn_segs = fn + 'TRUE_scan_p' + str(n + 1) + '_r' + str(r + 1) + '.png' plot_scan(X[30:-30, 30:-30, 0], savefn=fn_segs) fn_segs = fn + 'TRUE_segs_p' + str(n + 1) + '_r' + str(r + 1) + '.png' plot_segmentation(Y[30:-30, 30:-30], savefn=fn_segs) '''Scikit's VB GMM''' # Initialize model model = BayesianGaussianMixture(n_components=K, max_iter=max_iter, verbose=3) # Fit model model.fit(X.reshape((-1, 1))) # Segment image Y_h = model.predict(X.reshape((-1, 1))).reshape((H, W)) # Obtain posteriors post = model.predict_proba(X.reshape((-1, 1))).reshape((H, W, K))