if cfg.export_gramag: export_gradient_magnitude_image(gra, nii.get_filename(), nii.affine) # Reshape ima (more intuitive for voxel-wise operations) ima = np.ndarray.flatten(orig) gra = np.ndarray.flatten(gra) # """Plots""" print("Preparing GUI...") # Plot 2D histogram fig = plt.figure(facecolor='0.775') ax = fig.add_subplot(121) counts, volHistH, d_min, d_max, nr_bins, bin_edges \ = prep_2D_hist(ima, gra, discard_zeros=cfg.discard_zeros) ax.set_xlim(d_min, d_max) ax.set_ylim(d_min, d_max) ax.set_xlabel("Intensity f(x)") ax.set_ylabel("Gradient Magnitude f'(x)") ax.set_title("2D Histogram") # Plot map for poltical borders pltMap = np.zeros((nr_bins, nr_bins, 1)).repeat(4, 2) cmapPltMap = ListedColormap([[1, 1, 1, 0], # transparent zeros [0, 0, 0, 0.75], # political borders [1, 0, 0, 0.5], # other colors for future use [0, 0, 1, 0.5]]) boundsPltMap = [0, 1, 2, 3, 4] normPltMap = BoundaryNorm(boundsPltMap, cmapPltMap.N)
if cfg.export_gramag: export_gradient_magnitude_image(gra, nii.get_filename(), cfg.gramag, nii.affine) # Reshape for voxel-wise operations ima = np.copy(orig.flatten()) gra = gra.flatten() # """Plots""" print("Preparing GUI...") # Plot 2D histogram fig = plt.figure(facecolor='0.775') ax = fig.add_subplot(121) counts, volHistH, d_min, d_max, nr_bins, bin_edges \ = prep_2D_hist(ima, gra, discard_zeros=cfg.discard_zeros) # Set x-y axis range to the same (x-axis range) ax.set_xlim(d_min, d_max) ax.set_ylim(d_min, d_max) ax.set_xlabel("Intensity f(x)") ax.set_ylabel("Gradient Magnitude f'(x)") ax.set_title("2D Histogram") # Plot colorbar for 2D hist volHistH.set_norm(LogNorm(vmax=np.power(10, cfg.cbar_init))) fig.colorbar(volHistH, fraction=0.046, pad=0.04) # magical scaling # Plot 3D ima by default ax2 = fig.add_subplot(122) sliceNr = int(0.5 * dims[2])