From 3952ad03634e80b0f991ff71acf0cfac9aa9a458 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 27 Apr 2022 16:09:58 +0200 Subject: [PATCH] Add an overlay plot of Orientation field & cell image & fiber image to analysis --- CompactionAnalyzer/CompactionFunctions.py | 17 +++++++++++++++++ CompactionAnalyzer/plotting.py | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/CompactionAnalyzer/CompactionFunctions.py b/CompactionAnalyzer/CompactionFunctions.py index d7560c0..dac369a 100644 --- a/CompactionAnalyzer/CompactionFunctions.py +++ b/CompactionAnalyzer/CompactionFunctions.py @@ -654,6 +654,20 @@ def StuctureAnalysisMain(fiber_list, path_png= os.path.join(figures,"Orientation_weighted_noquiver.png"), label="Orientation",dpi=dpi) plt.close("all") + + ### more fancy overlay plot of cell & fiber & orientation (notweighted) + plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge], + im_cell_n[edge:-edge,edge:-edge], + orientation_dev, + path_png= os.path.join(figures,"Orientation_overlay.png"), + label="Orientation",dpi=dpi, + # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here + # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4, + omin=-1, omax=1,scale=scale) + + plt.close("all") + + # Polar plots plot_polar(results_angle['Angles Plotting'], results_angle['Coherency (weighted by intensity)'], path_png= os.path.join(figures,"polar_coherency_weighted.png"), label = "Coherency (weighted)",dpi=dpi) @@ -698,6 +712,9 @@ def StuctureAnalysisMain(fiber_list, vec1=min_evec[:,:,1], coherency_map=ori,show_n=10, segmention=segmention["mask"][edge:-edge,edge:-edge], path_png=os.path.join(figures,"overlay2.png"),dpi=dpi ,scale=scale) + ## + + plt.close("all") ### DISTANCE PLOTS # plot shells - deactived as it consumes a lot of time diff --git a/CompactionAnalyzer/plotting.py b/CompactionAnalyzer/plotting.py index 319b8d6..3de138b 100644 --- a/CompactionAnalyzer/plotting.py +++ b/CompactionAnalyzer/plotting.py @@ -140,6 +140,26 @@ def plot_coherency(coherency,path_png,label="Coherency",dpi=300): plt.axis('off'); cbar.set_label(label,fontsize=12) plt.savefig(path_png, dpi=dpi, bbox_inches='tight', pad_inches=0); plt.tight_layout() return fig + + +def plot_fancy_overlay(fiber, cell, field,path_png,label="field",dpi=300,cmap_cell="Greys_r",cmap_fiber="Greys_r", + cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4, # example cmaps: viridis/inferno/coolwarm + omin=-1, omax=1, scale=None): + fig =plt.figure() + plt.imshow(field,cmap=cmap_angle,vmin=omin,vmax=omax,alpha=alpha_ori);cbar =plt.colorbar() + plt.imshow(fiber, cmap=cmap_fiber,alpha=alpha_fiber) + plt.imshow(cell, cmap=cmap_cell,alpha=alpha_cell) + plt.axis('off'); + cbar.set_label(label,fontsize=12) + if scale is not None: + scalebar = ScaleBar(scale, "um", length_fraction=0.1, location="lower right", box_alpha=0 , + color="k") + plt.gca().add_artist(scalebar) + plt.tight_layout() + plt.savefig(path_png, dpi=dpi, bbox_inches='tight', pad_inches=0) + return fig + + def plot_polar(angle_plotting, something, path_png,label="something",dpi=300, something2 = None, something3 = None, label2 = None, label3 =None):