@@ -260,7 +260,8 @@ def StuctureAnalysisMain(fiber_list,
260260 manual_segmention = False , # segmentation of mask by manual clicking the cell outline
261261 plotting = True , # creates and saves individual figures additionally to the excel files
262262 dpi = 200 , # resolution of figures
263- SaveNumpy = False , # saves numpy arrays for later analysis - can create large data files
263+ SaveNumpy = True , # saves numpy arrays for later analysis
264+ SaveExcel = True , # saves Excel files for later analysis
264265 norm1 = 1 ,norm2 = 99 , # contrast spreading for input images between norm1- and norm2-percentile; values below norm1-percentile are set to zero and
265266 # values above norm2-percentile are set to 1
266267 ### use norm1= 0,norm2 = 100 if no contras enhancement desired
@@ -270,7 +271,13 @@ def StuctureAnalysisMain(fiber_list,
270271 segmention_min_area = 1000 , # small bjects below this px-area are removed during cell segmentation
271272 load_segmentation = False , # if True enter the path of the segementation.npy - file in path_seg
272273 path_seg = None , # to load a mask
273- ignore_cell_outline = False ): # if True the cell area is not set to nan and orientation are calculted everywhere - still the cell center is calculated from segmention
274+ ignore_cell_outline = False , # if True the cell area is not set to nan and orientation are calculted everywhere - still the cell center is calculated from segmention
275+
276+
277+ mode_saenopy = False ): # only used for the Saenopy Version to return data files directly after single run
278+
279+
280+
274281 """
275282 Main analysis
276283
@@ -491,7 +498,8 @@ def StuctureAnalysisMain(fiber_list,
491498 results_total ['Orientation (weighted by intensity and coherency)' ].append (cos_dev_total3 )
492499
493500 excel_total = pd .DataFrame .from_dict (results_total )
494- excel_total .to_excel (os .path .join (out_list [n ],"results_total.xlsx" ))
501+ if SaveExcel :
502+ excel_total .to_excel (os .path .join (out_list [n ],"results_total.xlsx" ))
495503
496504
497505 """
@@ -546,14 +554,18 @@ def StuctureAnalysisMain(fiber_list,
546554
547555 # create excel sheet with results for angle analysis
548556 excel_angles = pd .DataFrame .from_dict (results_angle )
549- excel_angles . to_excel ( os . path . join ( out_list [ n ], "results_angles.xlsx" ))
550-
557+ if SaveExcel :
558+ excel_angles . to_excel ( os . path . join ( out_list [ n ], "results_angles.xlsx" ))
551559
560+
552561 """
553562 Distance Evaluation
554563 """
555564
556- # initialize result dictionary
565+
566+ # def distance_analysis(shells,shell_width,dist_surface,scale,angle_dev, ori, orientation_dev, weight_image,im_fiber_g):
567+
568+ # initialize result dictionary
557569 results_distance = {'Shell_mid (px)' : [], 'Shell_mid (µm)' : [], 'Intensity (accumulated)' : [],
558570 'Intensity (individual)' : [], 'Intensity Norm (individual)' : [],
559571 'Intensity Norm (accumulated)' : [], 'Angle (accumulated)' : [], 'Angle (individual)' : [], 'Angle (individual-weightInt)' : [],
@@ -565,7 +577,7 @@ def StuctureAnalysisMain(fiber_list,
565577 'Angle disttocenter (accumulated)' : [], 'Angle disttocenter (individual)' : [],
566578 'Orientation disttocenter (accumulated)' : [], 'Orientation disttocenter (individual)' : [],
567579 'Angle disttocenter (individual)' : []
568- }
580+ }
569581
570582 mask_shells = {'Mask_shell' : [], 'Mask_shell_center' : [] }
571583 # shell distances
@@ -598,7 +610,7 @@ def StuctureAnalysisMain(fiber_list,
598610 results_distance ['Orientation (individual-weightInt)' ].append (np .nanmean (orientation_dev [mask_shell ]* ori [mask_shell ]* weight_image [mask_shell ]/ np .nanmean (ori [mask_shell ]* weight_image [mask_shell ]) ))
599611
600612
601- # mean intensity
613+ # mean intensity
602614 results_distance ['Intensity (accumulated)' ].append (np .nanmean (im_fiber_g [mask_shell_lower ])) # accumulation of lower shells
603615 results_distance ['Intensity (individual)' ].append (np .nanmean (im_fiber_g [mask_shell ]) ) # exclusively in certain shell
604616
@@ -632,7 +644,8 @@ def StuctureAnalysisMain(fiber_list,
632644 results_distance ['Intensity Norm disttocenter (accumulated)' ].extend (list (norm_accum_int_c ) )
633645 # create excel sheet with results for angle analysis
634646 excel_distance = pd .DataFrame .from_dict (results_distance )
635- excel_distance .to_excel (os .path .join (out_list [n ],"results_distance.xlsx" ))
647+ if SaveExcel :
648+ excel_distance .to_excel (os .path .join (out_list [n ],"results_distance.xlsx" ))
636649
637650
638651
@@ -661,11 +674,11 @@ def StuctureAnalysisMain(fiber_list,
661674 #np.save(os.path.join(numpy_out, "mask_surface_shells.npy"),mask_shells['Mask_shell'])
662675 #np.save(os.path.join(numpy_out, "mask_spherical_shells.npy"),mask_shells['Mask_shell_center'])
663676
664- # check the shapes --> everything is the same format
665- # print(segmention["mask"][edge:-edge,edge:-edge].shape)
666- # print(orientation_dev.shape)
667- # print(normalize(im_fiber_n[edge:-edge,edge:-edge]).shape)
668- # print(angle_no_reference.shape)
677+ # check the shapes --> everything is the same format
678+ # print(segmention["mask"][edge:-edge,edge:-edge].shape)
679+ # print(orientation_dev.shape)
680+ # print(normalize(im_fiber_n[edge:-edge,edge:-edge]).shape)
681+ # print(angle_no_reference.shape)
669682
670683
671684 """
@@ -682,25 +695,7 @@ def StuctureAnalysisMain(fiber_list,
682695 plot_angle_dev (angle_map = orientation_dev , vmin = - 1 ,vmax = 1 ,
683696 vec0 = min_evec [:,:,0 ] ,vec1 = min_evec [:,:,1 ] ,coherency_map = ori ,
684697 path_png = os .path .join (figures ,"Orientation.png" ),label = "Orientation" ,dpi = dpi ,cmap = "coolwarm" )
685- # plot orientation and angle deviation maps together with orientation structure
686- # plot_angle_dev(angle_map = angle_dev, vmin=0,vmax=90,
687- # vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
688- # path_png= os.path.join(figures,"Angle_deviation.png"),label="Angle Deviation",dpi=dpi,cmap="viridis_r")
689-
690- # # do not show the weighted ones here, as only the mean has the same range again and here angles can be smaller/large
691- # plot_angle_dev(angle_map = angle_dev_weighted2,
692- # vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
693- # path_png= os.path.join(figures,"Angle_deviation_weighted.png"),label="Angle Deviation",dpi=dpi,cmap="viridis_r")
694- # plot_angle_dev(angle_map = orientation_dev_weighted2 ,
695- # vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
696- # path_png= os.path.join(figures,"Orientation_weighted.png"),label="Orientation",dpi=dpi,cmap="viridis")
697-
698- # # pure coherency and pure orientation
699- # plot_coherency(ori,path_png= os.path.join(figures,"coherency_noquiver.png"),
700- # label="Coherency",vmin=0,vmax=1,cmap="turbo",dpi=dpi)
701- # plot_coherency(orientation_dev,
702- # path_png= os.path.join(figures,"Orientation_noquiver.png"),
703- # label="Orientation",vmin=-1,vmax=1,cmap="coolwarm",dpi=dpi)
698+
704699
705700
706701 if cell_list == None :
@@ -726,8 +721,6 @@ def StuctureAnalysisMain(fiber_list,
726721 orientation_dev , cmap_angle = "coolwarm" ,
727722 path_png = os .path .join (figures ,"Orientation_overlay.png" ),
728723 label = "Orientation" ,dpi = dpi ,
729- # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
730- # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
731724 omin = - 1 , omax = 1 ,scale = scale )
732725
733726 else :
@@ -771,7 +764,6 @@ def StuctureAnalysisMain(fiber_list,
771764
772765
773766 plt .close ("all" )
774-
775767
776768 # Polar plots
777769 plot_polar (results_angle ['Angles Plotting' ], results_angle ['Coherency (weighted by intensity)' ],
@@ -807,7 +799,6 @@ def StuctureAnalysisMain(fiber_list,
807799 path_png = os .path .join (figures ,"fiber_structure.png" ),dpi = dpi ,scale = scale )
808800
809801
810-
811802 plt .close ("all" )
812803 ### DISTANCE PLOTS
813804 # plot shells - deactived as it consumes a lot of time
@@ -825,8 +816,10 @@ def StuctureAnalysisMain(fiber_list,
825816 plot_cell (im_cell_n , path_png = os .path .join (figures ,"cell-raw.png" ), scale = scale , dpi = dpi )
826817 plot_cell (normalize (im_fiber_n [edge :- edge ,edge :- edge ]), path_png = os .path .join (figures ,"fiber-raw.png" ), scale = scale , dpi = dpi )
827818
828- plt .close ("all" )
829-
819+ plt .close ("all" )
820+
821+ if mode_saenopy == True : # only evaluates a single item at each call and returns the arrays
822+ return excel_total , excel_angles , excel_distance
830823 return
831824
832825
0 commit comments