CompactionAnalyzer 1.0.2__tar.gz → 1.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/CompactionAnalyzer/CompactionFunctions.py +251 -160
  2. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/CompactionAnalyzer/QtShortCuts.py +527 -58
  3. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/CompactionAnalyzer/StructureTensor.py +4 -1
  4. compactionanalyzer-1.0.4/CompactionAnalyzer/__init__.py +7 -0
  5. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/CompactionAnalyzer/plotting.py +40 -22
  6. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/CompactionAnalyzer/utilities.py +7 -5
  7. compactionanalyzer-1.0.4/CompactionAnalyzer.egg-info/PKG-INFO +21 -0
  8. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/CompactionAnalyzer.egg-info/SOURCES.txt +1 -1
  9. compactionanalyzer-1.0.4/CompactionAnalyzer.egg-info/requires.txt +10 -0
  10. compactionanalyzer-1.0.4/PKG-INFO +21 -0
  11. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/README.md +66 -19
  12. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/setup.py +8 -5
  13. CompactionAnalyzer-1.0.2/CompactionAnalyzer/__init__.py +0 -7
  14. CompactionAnalyzer-1.0.2/CompactionAnalyzer.egg-info/PKG-INFO +0 -11
  15. CompactionAnalyzer-1.0.2/CompactionAnalyzer.egg-info/requires.txt +0 -5
  16. CompactionAnalyzer-1.0.2/PKG-INFO +0 -11
  17. /CompactionAnalyzer-1.0.2/CompactionAnalyzer/GUI.py → /compactionanalyzer-1.0.4/CompactionAnalyzer/GUI_old_use_saenopy_instead.py +0 -0
  18. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/CompactionAnalyzer/QExtendedGraphicsView.py +0 -0
  19. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/CompactionAnalyzer.egg-info/dependency_links.txt +0 -0
  20. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/CompactionAnalyzer.egg-info/top_level.txt +0 -0
  21. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/LICENSE +0 -0
  22. {CompactionAnalyzer-1.0.2 → compactionanalyzer-1.0.4}/setup.cfg +0 -0
@@ -2,12 +2,17 @@ import numpy as np
2
2
  from skimage import io
3
3
  from PIL import Image
4
4
  from skimage.filters import gaussian, threshold_otsu, threshold_yen
5
- import scipy.ndimage.morphology as scipy_morph
6
- import scipy.ndimage.measurements as scipy_meas
7
5
  from skimage.morphology import remove_small_objects
8
6
  import imageio
9
7
  from skimage import color
10
- from scipy.ndimage.morphology import distance_transform_edt
8
+ try:
9
+ from scipy.ndimage import distance_transform_edt
10
+ import scipy.ndimage as scipy_morph
11
+ import scipy.ndimage as scipy_meas
12
+ except ImportError:
13
+ from scipy.ndimage.morphology import distance_transform_edt
14
+ import scipy.ndimage.morphology as scipy_morph
15
+ import scipy.ndimage.measurements as scipy_meas
11
16
  import matplotlib.pyplot as plt
12
17
  import os
13
18
  import pandas as pd
@@ -69,6 +74,15 @@ def custom_mask(img,show_segmentation=True):
69
74
  dict: Dictionary with keys: mask, radius, centroid (x/y)
70
75
  """
71
76
  from roipoly import RoiPoly
77
+ import matplotlib
78
+
79
+ # switch backend for roipoly
80
+ try:
81
+ mpl_backend = matplotlib.get_backend()
82
+ matplotlib.use('Qt5Agg')
83
+ except:
84
+ print ("Switched to Qt5Agg Backend for Roipoly")
85
+
72
86
  # need to install RoiPoly package via pip to use this function
73
87
  height = img.shape[0]
74
88
  width = img.shape[1]
@@ -93,7 +107,15 @@ def custom_mask(img,show_segmentation=True):
93
107
  # if show_segmentation:
94
108
  # plt.figure()
95
109
  # plt.subplot(121), plt.imshow(img)
96
- # plt.subplot(122), plt.imshow(mask)
110
+ # plt.subplot(122), plt.imshow(mask)
111
+
112
+ # switch to original backend
113
+ try:
114
+ matplotlib.use(mpl_backend)
115
+ print ("Switched Back")
116
+ except:
117
+ print ("Could not switched back")
118
+
97
119
  return {'mask': mask, 'radius': radius, 'centroid': (cx, cy)}
98
120
 
99
121
  def regional_maxima(img):
@@ -195,6 +217,24 @@ def segment_cell(img, thres=1, seg_gaus1 = 0.5, seg_gaus2=100, seg_iter=1,show_s
195
217
  return {'mask': mask, 'radius': radius, 'centroid': (cx, cy)}
196
218
 
197
219
 
220
+ def create_centered_circle(image_shape):
221
+ # Extract the height and width of the image
222
+ height, width = image_shape[:2]
223
+ # Calculate the center of the image
224
+ center_y, center_x = height // 2, width // 2
225
+ # Calculate the radius of the circle (1/4 of the image height or width)
226
+ radius = min(height, width) // 10
227
+ # Create a 2D array of zeros (background)
228
+ circle_array = np.zeros((height, width), dtype=int)
229
+ # Iterate over each point in the 2D array
230
+ for y in range(height):
231
+ for x in range(width):
232
+ # Calculate the distance from the center
233
+ distance = np.sqrt((y - center_y) ** 2 + (x - center_x) ** 2)
234
+ # If the distance is less than or equal to the radius, set it to 1 (circle)
235
+ if distance <= radius:
236
+ circle_array[y, x] = 1
237
+ return circle_array
198
238
 
199
239
 
200
240
  def StuctureAnalysisMain(fiber_list,
@@ -204,10 +244,11 @@ def StuctureAnalysisMain(fiber_list,
204
244
  sigma_tensor = None , # sigma of applied gauss filter / window for structure tensor analysis in px
205
245
  # should be in the order of the objects to analyze !!
206
246
  # 7 um for collagen
207
- edge = 40 , # Cutt of pixels at the edge since values at the border cannot be trusted
247
+ edge = 15 , # Cutt of pixels at the edge since values at the border cannot be trusted
208
248
  segmention_thres = 1.0 , # for cell segemetntion, thres 1 equals normal otsu threshold , user also can specify gaus1 + gaus2 in segmentation if needed
209
249
  seg_gaus1=0.5, seg_gaus2 = 100 , # 2 gaus filters used as bandpassfilter for local contrast enhancement; For seg_gaus2 = None a single gauss filter is applied
210
250
  max_dist = None, # optional: specify the maximal distance around cell center for analysis (in px)
251
+ min_dist = None, # optional: specify the minimals distance around cell center for analysis (in px)
211
252
  regional_max_correction = True,# background correction using regional maxima approach
212
253
  show_segmentation = False , # display the segmentation output
213
254
  sigma_first_blur = 0.5 , # slight first bluring of whole image before appplying the structure tensor
@@ -219,6 +260,7 @@ def StuctureAnalysisMain(fiber_list,
219
260
  SaveNumpy = False , # saves numpy arrays for later analysis - can create large data files
220
261
  norm1=1,norm2 = 99 , # contrast spreading for input images between norm1- and norm2-percentile; values below norm1-percentile are set to zero and
221
262
  # values above norm2-percentile are set to 1
263
+ ### use norm1= 0,norm2 = 100 if no contras enhancement desired
222
264
  seg_invert=False, # if segmentation is inverted dark objects are detected inseated of bright objects
223
265
  seg_iter = 1, # number of repetitions of binary closing, dilation and filling holes steps
224
266
  segmention_method="otsu", # use "otsu", "entropy" or "yen" as segmentation method
@@ -240,8 +282,16 @@ def StuctureAnalysisMain(fiber_list,
240
282
  None.
241
283
 
242
284
  """
243
- plt.ioff()
244
- # plt.ion()
285
+ # plt.ioff()
286
+ # plt.ion()
287
+
288
+ # if no cell images are specified we conduct the analyis on the full image
289
+ # for this, we create dummy images of an artificial cell and set ignore_cell_outline to True
290
+ # Might be usefull to look at quantities such as fiber coherency or angle towards x-axis
291
+ if cell_list == None:
292
+ ignore_cell_outline= True
293
+ dummy_cell = create_centered_circle(imageio.v2.imread(fiber_list[0]).shape)
294
+
245
295
 
246
296
  # if not specified use 7um for tensor analysis and 5um shells
247
297
  if not sigma_tensor:
@@ -269,30 +319,34 @@ def StuctureAnalysisMain(fiber_list,
269
319
  'SaveNumpy': [SaveNumpy], 'norm1': [norm1], 'norm2': [norm2],
270
320
  'seg_invert': [seg_invert], 'seg_iter': [seg_iter], 'segmention_method': [segmention_method],
271
321
  'load_segmentation': [load_segmentation], 'path_seg': [path_seg],
272
- 'max_dist': [max_dist]
322
+ 'max_dist': [max_dist], 'min_dist': [min_dist]
273
323
 
274
324
  },
275
325
  'Data' : {'fiber_list': [fiber_list], 'cell_list': [cell_list], 'out_list': [out_list]}
276
326
  }
277
327
  with open(os.path.join(out_list[n],"parameters.yml"), 'w') as yaml_file:
278
328
  yaml.dump(dict_file, yaml_file, default_flow_style=False)
279
-
280
329
 
281
- # load images
282
- im_cell = imageio.imread(cell_list[n]) #color.rgb2gray(..)
283
- im_fiber = imageio.imread(fiber_list[n]) #color.rgb2gray()
330
+ # load images
331
+ im_fiber = imageio.v2.imread(fiber_list[n]) #color.rgb2gray()
332
+ if cell_list == None:
333
+ im_cell = dummy_cell
334
+ else:
335
+ im_cell = imageio.v2.imread(cell_list[n])
336
+
284
337
 
285
338
  ## if 3 channels convert to grey
286
- if len(im_cell.shape) == 3 :
339
+ if len(im_cell.shape) == 3 :
287
340
  im_cell = color.rgb2gray(im_cell)
288
341
  if len(im_fiber.shape) == 3 :
289
- im_fiber = color.rgb2gray(im_fiber)
290
-
342
+ im_fiber = color.rgb2gray(im_fiber)
343
+
344
+
291
345
  # # applying normalizing/ contrast spreading
292
346
  im_cell_n = normalize(im_cell, norm1, norm2)
293
347
  im_fiber_n = normalize(im_fiber, norm1, norm2)
294
348
  im_fiber_g = gaussian(im_fiber_n, sigma=sigma_first_blur) # blur fiber image slightly (test with local gauss - similar)
295
-
349
+
296
350
 
297
351
  # segment cell (either manual or automatically)
298
352
  if manual_segmention==True:
@@ -326,10 +380,13 @@ def StuctureAnalysisMain(fiber_list,
326
380
  # Structure Tensor Orientation
327
381
  # get structure tensor
328
382
  ori, max_evec, min_evec, max_eval, min_eval = analyze_local(im_fiber_g_forstructure, sigma=sigma_tensor, size=0, filter_type="gaussian")
383
+
329
384
  # cut off edges as specified
330
385
  if edge != 0:
331
386
  ori, max_evec, min_evec, max_eval, min_eval = ori[edge:-edge,edge:-edge], max_evec[edge:-edge,edge:-edge], min_evec[edge:-edge,edge:-edge], \
332
387
  max_eval[edge:-edge,edge:-edge], min_eval[edge:-edge,edge:-edge]
388
+
389
+
333
390
  """
334
391
  coordinates
335
392
  """
@@ -342,31 +399,32 @@ def StuctureAnalysisMain(fiber_list,
342
399
  dx_norm = (dx/distance)
343
400
  dy_norm = (dy/distance)
344
401
  dist_surface = distance_transform_edt(~segmention["mask"])[edge:-edge,edge:-edge] # dist to surface
345
-
346
-
402
+ # calculate an angle without the deviation/reference to the cell position
403
+ angle_no_reference = np.abs(np.arctan2(min_evec[:,:,0],min_evec[:,:,1])*360/(2*np.pi))-90 # -90 to +90° towards x-axis
404
+
405
+
347
406
  """
348
407
  total image analysis
349
408
  """
350
409
  # Angular deviation from orietation to center vector (projection to only have positive deviation angle values since negative/positive deviation does not matter here)
351
410
  angle_dev = np.arccos(np.abs(dx_norm * min_evec[:,:,0] + dy_norm*min_evec[:,:,1])) * 360/(2*np.pi)
352
- # calculate oreination from angle_dev since they are normal distributed and np.abs((dx_norm * min_evec[:,:,0] + dy_norm*min_evec[:,:,1])) is not
353
- orientation_dev_01 = angle_dev/90
354
- # orientation_dev_01 = np.abs((dx_norm * min_evec[:,:,0] + dy_norm*min_evec[:,:,1]))
355
- orientation_dev = -(2*orientation_dev_01-1) # norm from -1 to 1 ; changed sign
356
-
411
+ ## compute the orientation
412
+ orientation_dev = 1 - (2 * np.arccos(np.abs(dx_norm * min_evec[:,:,0] + dy_norm*min_evec[:,:,1]))/ (0.5* np.pi))
413
+
414
+
357
415
  ### set values to nan if max distance is specified
358
416
  ## for following analysis then only orientation within a certtain distance to the cell are used
359
417
  if max_dist:
360
- angle_dev[distance>=max_dist] = np.nan
361
- ori[distance>=max_dist] = np.nan
362
- angle[distance>=max_dist] = np.nan # also for angular evaluation
418
+ angle_dev[distance>max_dist] = np.nan
419
+ ori[distance>max_dist] = np.nan
420
+ angle[distance>max_dist] = np.nan # also for angular evaluation
363
421
 
364
- # weighting by coherence
365
- angle_dev_weighted = (angle_dev * ori) / np.nanmean(ori) # no angle values anymore (stretched due weights) but the mean later is again an angle
366
- orientation_dev_weighted_01 = ((orientation_dev_01 * ori) / np.nanmean(ori))
367
- orientation_dev_weighted = -(2 *orientation_dev_weighted_01 - 1)
368
-
369
-
422
+ if min_dist:
423
+ angle_dev[distance<min_dist] = np.nan
424
+ ori[distance<min_dist] = np.nan
425
+ angle[distance<max_dist] = np.nan # also for angular evaluation
426
+
427
+
370
428
  # weighting by coherence and image intensity
371
429
  im_fiber_g = im_fiber_g[edge:-edge,edge:-edge]
372
430
  # could also use non filtered image
@@ -374,14 +432,18 @@ def StuctureAnalysisMain(fiber_list,
374
432
  # use a threshold in the intensity image// only coherence and orientation vectors
375
433
  # corresponding to pixels in the intesity iamage above a threshold are considered.
376
434
  weight_image = gaussian(im_fiber_g,sigma=15)
435
+
436
+ # construct weighted array so that the mean value of these arrays later
437
+ # result in the weighted average of these
438
+ # weight by coherency
439
+ angle_dev_weighted = (angle_dev * ori) / np.nanmean(ori)
440
+ orientation_dev_weighted = (orientation_dev * ori) / np.nanmean(ori)
441
+ # weight by coherency & intensity
377
442
  angle_dev_weighted2 = (angle_dev_weighted *weight_image) / np.nanmean(weight_image)
378
- orientation_dev_weighted2_01 = (orientation_dev_01 *weight_image*ori) / np.nanmean(weight_image*ori)
379
- orientation_dev_weighted2 = -(2 * orientation_dev_weighted2_01 - 1)
380
-
381
- # also weighting the coherency like this
443
+ orientation_dev_weighted2 = (orientation_dev *weight_image*ori) / np.nanmean(weight_image*ori)
444
+ # weighting coherency by intensity
382
445
  ori_weight2 = (ori * weight_image) / np.nanmean(weight_image)
383
-
384
-
446
+
385
447
  # GRADIENT towards center
386
448
  grad_y = np.gradient(im_fiber_g, axis=0)
387
449
  grad_x = np.gradient(im_fiber_g, axis=1)
@@ -402,9 +464,7 @@ def StuctureAnalysisMain(fiber_list,
402
464
  alpha_dev_total1 = np.nanmean(angle_dev[(~segmention["mask"][edge:-edge,edge:-edge])])
403
465
  alpha_dev_total2 = np.nanmean(angle_dev_weighted[(~segmention["mask"][edge:-edge, edge:-edge])])
404
466
  alpha_dev_total3 = np.nanmean(angle_dev_weighted2[(~segmention["mask"][edge:-edge, edge:-edge])])
405
- # cos_dev_total1 = np.nanmean(np.cos(2*angle_dev[(~segmention["mask"][edge:-edge, edge:-edge])]*np.pi/180))
406
- # cos_dev_total2 = np.nanmean(np.cos(2*angle_dev_weighted[(~segmention["mask"][edge:-edge, edge:-edge])]*np.pi/180))
407
- # cos_dev_total3 = np.nanmean(np.cos(2*angle_dev_weighted2[(~segmention["mask"][edge:-edge, edge:-edge])]*np.pi/180))
467
+
408
468
  cos_dev_total1 = np.nanmean(orientation_dev[(~segmention["mask"][edge:-edge,edge:-edge]) ])
409
469
  cos_dev_total2 = np.nanmean(orientation_dev_weighted[(~segmention["mask"][edge:-edge,edge:-edge]) ])
410
470
  cos_dev_total3 = np.nanmean(orientation_dev_weighted2[(~segmention["mask"][edge:-edge,edge:-edge]) ])
@@ -571,59 +631,40 @@ def StuctureAnalysisMain(fiber_list,
571
631
  excel_distance = pd.DataFrame.from_dict(results_distance)
572
632
  excel_distance.to_excel(os.path.join(out_list[n],"results_distance.xlsx"))
573
633
 
574
-
575
- # Halflife values - Leave for now..
576
- # # Calculate value where ntensity drops 25%
577
- # distintdrop = np.abs(np.array(results_distance['Intensity Norm (individual)'])-0.75)
578
- # # distance where int drops to 75%
579
- # halflife_int = midofshells[np.where(distintdrop == np.nanmin(distintdrop))[1]]
580
- # # if decrease is not within range (minimum equals last value) then set to nan
581
- # if halflife_int == midofshells[-1]:
582
- # halflife_int = np.nan
583
- # # # Calculate value where orientation drops to 75% within maxorientation(min) to 45° (random) range
584
- # # difference to 45 degree instead of min-max range
585
- # # calculate halflife of maximal orientation over distance
586
- # # difference to 45 degree for all
587
- # diffdist = np.array(dist_angle_individ)-45
588
- # # maximal orientation
589
- # diffmax = np.nanmin(diffdist)
590
- # diffmax_pos = np.where(diffmax==diffdist)[0][0]
591
- # # difference angle drops to 75%
592
- # diff2 = np.abs(diffdist-(0.75*diffmax))
593
- # diff2[:diffmax_pos] = np.nan # only look at distances on the right side /further out
594
- # halflife_ori = midofshells[np.where(diff2 == np.nanmin(diff2))]
595
- # # if decrease is not within range (minimum equals last value) then set to nan
596
- # if halflife_ori == midofshells[-1]:
597
- # halflife_ori = np.nan
598
- # try:
599
- # np.savetxt(os.path.join(out_list[n],"meanangle_within10shells.txt"), [dist_angle_accum[9]])
600
- # except:
601
- # pass
634
+
602
635
 
603
636
  if SaveNumpy:
604
637
  #create output folder if not existing
605
- numpy_out = os.path.join(out_list[n], r"NumpyArrays" )
638
+ numpy_out = os.path.join(out_list[n], "NumpyArrays" )
639
+ print (numpy_out)
606
640
  if not os.path.exists(numpy_out):
607
641
  os.makedirs(numpy_out)
608
-
609
- np.save(os.path.join(numpy_out, "segmention.npy" ),segmention)
610
- np.save(os.path.join(numpy_out, "AngleMap.npy" ),angle_dev )
611
- np.save(os.path.join(numpy_out, "AngleMap(weight_int).npy" ),angle_dev_weighted)
612
- np.save(os.path.join(numpy_out, "AngleMap(weight_int_coh).npy"),angle_dev_weighted2 )
642
+ # save data array all with the size of the evaluated arrays
643
+ # that are "edge" - pixels smaller to get rid of boundary artefacts
644
+ np.save(os.path.join(numpy_out, "segmention.npy" ),segmention["mask"][edge:-edge,edge:-edge])
645
+ np.save(os.path.join(numpy_out, "AngleDeviationMap.npy" ),angle_dev )
646
+ #np.save(os.path.join(numpy_out, "AngleMap(weight_int).npy" ),angle_dev_weighted)
647
+ np.save(os.path.join(numpy_out, "AngleDeviationMap(weight_int_coh).npy"),angle_dev_weighted2 )
648
+ np.save(os.path.join(numpy_out, "AngleMap_NoReference.npy"), angle_no_reference )
613
649
  np.save(os.path.join(numpy_out, "OrientationMap.npy" ),orientation_dev )
614
- np.save(os.path.join(numpy_out, "OrientationMap_weight_int.npy" ),orientation_dev_weighted)
650
+ #np.save(os.path.join(numpy_out, "OrientationMap_weight_int.npy" ),orientation_dev_weighted)
615
651
  np.save(os.path.join(numpy_out, "OrientationMap_weight_intcoh.npy" ),orientation_dev_weighted2 )
616
652
  np.save(os.path.join(numpy_out, "FiberImageCrop.npy" ),normalize(im_fiber_n[edge:-edge,edge:-edge]) )
617
653
  np.save(os.path.join(numpy_out, "CoherencyMap.npy" ),ori )
618
- np.save(os.path.join(numpy_out, "CoherencyMap(weighted_int).npy" ),ori_weight2)
654
+ #np.save(os.path.join(numpy_out, "CoherencyMap(weighted_int).npy" ),ori_weight2)
619
655
  np.save(os.path.join(numpy_out, "Vector_min_ax0.npy"),min_evec[:,:,0])
620
656
  np.save(os.path.join(numpy_out, "Vector_min_ax1.npy"),min_evec[:,:,1])
621
- np.save(os.path.join(numpy_out, "mask_surface_shells.npy"),mask_shells['Mask_shell'])
622
- np.save(os.path.join(numpy_out, "mask_spherical_shells.npy"),mask_shells['Mask_shell_center'])
623
-
624
-
625
-
626
-
657
+ np.save(os.path.join(numpy_out, "center.npy"),center_small)
658
+ #np.save(os.path.join(numpy_out, "mask_surface_shells.npy"),mask_shells['Mask_shell'])
659
+ #np.save(os.path.join(numpy_out, "mask_spherical_shells.npy"),mask_shells['Mask_shell_center'])
660
+
661
+ # check the shapes --> everything is the same format
662
+ # print(segmention["mask"][edge:-edge,edge:-edge].shape)
663
+ # print(orientation_dev.shape)
664
+ # print(normalize(im_fiber_n[edge:-edge,edge:-edge]).shape)
665
+ # print(angle_no_reference.shape)
666
+
667
+
627
668
  """
628
669
  Plott results
629
670
  """
@@ -631,90 +672,139 @@ def StuctureAnalysisMain(fiber_list,
631
672
  if plotting:
632
673
  #create output folder if not existing
633
674
  figures = os.path.join(out_list[n],"Figures")
675
+ print (figures)
634
676
  if not os.path.exists(figures):
635
677
  os.makedirs(figures)
636
-
678
+
679
+ plot_angle_dev(angle_map = orientation_dev, vmin=-1,vmax=1,
680
+ vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
681
+ path_png= os.path.join(figures,"Orientation.png"),label="Orientation",dpi=dpi,cmap="coolwarm")
637
682
  # plot orientation and angle deviation maps together with orientation structure
638
- plot_angle_dev(angle_map = angle_dev,
639
- vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
640
- path_png= os.path.join(figures,"Angle_deviation.png"),label="Angle Deviation",dpi=dpi,cmap="viridis_r")
641
- plot_angle_dev(angle_map = angle_dev_weighted2,
642
- vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
643
- path_png= os.path.join(figures,"Angle_deviation_weighted.png"),label="Angle Deviation",dpi=dpi,cmap="viridis_r")
644
- plot_angle_dev(angle_map = orientation_dev_weighted2 ,
645
- vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
646
- path_png= os.path.join(figures,"Orientation_weighted.png"),label="Orientation",dpi=dpi,cmap="viridis")
647
- plot_angle_dev(angle_map = orientation_dev,
648
- vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
649
- path_png= os.path.join(figures,"Orientation.png"),label="Orientation",dpi=dpi,cmap="viridis")
650
- plt.close("all")
651
- # pure coherency and pure orientation
652
- plot_coherency(ori,path_png= os.path.join(figures,"coherency_noquiver.png"))
653
- plot_coherency(orientation_dev_weighted2,
654
- path_png= os.path.join(figures,"Orientation_weighted_noquiver.png"),
655
- label="Orientation",dpi=dpi)
656
- plt.close("all")
683
+ # plot_angle_dev(angle_map = angle_dev, vmin=0,vmax=90,
684
+ # vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
685
+ # path_png= os.path.join(figures,"Angle_deviation.png"),label="Angle Deviation",dpi=dpi,cmap="viridis_r")
686
+
687
+ # # do not show the weighted ones here, as only the mean has the same range again and here angles can be smaller/large
688
+ # plot_angle_dev(angle_map = angle_dev_weighted2,
689
+ # vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
690
+ # path_png= os.path.join(figures,"Angle_deviation_weighted.png"),label="Angle Deviation",dpi=dpi,cmap="viridis_r")
691
+ # plot_angle_dev(angle_map = orientation_dev_weighted2 ,
692
+ # vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
693
+ # path_png= os.path.join(figures,"Orientation_weighted.png"),label="Orientation",dpi=dpi,cmap="viridis")
694
+
695
+ # # pure coherency and pure orientation
696
+ # plot_coherency(ori,path_png= os.path.join(figures,"coherency_noquiver.png"),
697
+ # label="Coherency",vmin=0,vmax=1,cmap="turbo",dpi=dpi)
698
+ # plot_coherency(orientation_dev,
699
+ # path_png= os.path.join(figures,"Orientation_noquiver.png"),
700
+ # label="Orientation",vmin=-1,vmax=1,cmap="coolwarm",dpi=dpi)
701
+
702
+
703
+ if cell_list == None:
704
+ plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
705
+ None,
706
+ angle_no_reference, cmap_angle="gist_rainbow",
707
+ path_png= os.path.join(figures,"Angle_NoReference_overlay_nocell.png"),
708
+ label="Angle (x-axis)",dpi=dpi,
709
+ # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
710
+ # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
711
+ omin=-90, omax=90,
712
+ scale=scale)
713
+ plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
714
+ None,
715
+ ori, cmap_angle="turbo",
716
+ path_png= os.path.join(figures,"Coherency_overlay_nocell.png"),
717
+ label="Coherency",dpi=dpi,
718
+ # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
719
+ # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
720
+ omin=0, omax=1,scale=scale)
721
+ plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
722
+ im_cell_n[edge:-edge,edge:-edge],
723
+ orientation_dev, cmap_angle="coolwarm",
724
+ path_png= os.path.join(figures,"Orientation_overlay.png"),
725
+ label="Orientation",dpi=dpi,
726
+ # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
727
+ # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
728
+ omin=-1, omax=1,scale=scale)
729
+
730
+ else:
731
+ ### more fancy overlay plot of cell & fiber & orientation (notweighted)
732
+ plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
733
+ im_cell_n[edge:-edge,edge:-edge],
734
+ orientation_dev, cmap_angle="coolwarm",
735
+ path_png= os.path.join(figures,"Orientation_overlay.png"),
736
+ label="Orientation",dpi=dpi,
737
+ # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
738
+ # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
739
+ omin=-1, omax=1,scale=scale)
740
+
741
+ plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
742
+ im_cell_n[edge:-edge,edge:-edge],
743
+ ori, cmap_angle="turbo",
744
+ path_png= os.path.join(figures,"Coherency_overlay.png"),
745
+ label="Coherency",dpi=dpi,
746
+ # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
747
+ # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
748
+ omin=0, omax=1,scale=scale)
749
+
750
+ plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
751
+ im_cell_n[edge:-edge,edge:-edge],
752
+ angle_dev, cmap_angle="viridis_r",
753
+ path_png= os.path.join(figures,"Angle_Deviation_overlay.png"),
754
+ label="Angle Deviation",dpi=dpi,
755
+ # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
756
+ # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
757
+ omin=0, omax=90,scale=scale)
758
+
759
+ plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
760
+ im_cell_n[edge:-edge,edge:-edge],
761
+ angle_no_reference, cmap_angle="gist_rainbow",
762
+ path_png= os.path.join(figures,"Angle_NoReference_overlay.png"),
763
+ label="Angle (x-axis)",dpi=dpi,
764
+ # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
765
+ # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
766
+ omin=-90, omax=90,
767
+ scale=scale)
768
+
657
769
 
658
- ### more fancy overlay plot of cell & fiber & orientation (notweighted)
659
- plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
660
- im_cell_n[edge:-edge,edge:-edge],
661
- orientation_dev,
662
- path_png= os.path.join(figures,"Orientation_overlay.png"),
663
- label="Orientation",dpi=dpi,
664
- # ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
665
- # cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
666
- omin=-1, omax=1,scale=scale)
667
-
668
770
  plt.close("all")
669
771
 
670
772
 
671
- # Polar plots
672
- plot_polar(results_angle['Angles Plotting'], results_angle['Coherency (weighted by intensity)'],
673
- path_png= os.path.join(figures,"polar_coherency_weighted.png"), label = "Coherency (weighted)",dpi=dpi)
674
-
675
-
773
+ # Polar plots
676
774
  plot_polar(results_angle['Angles Plotting'], results_angle['Coherency (weighted by intensity)'],
677
775
  path_png= os.path.join(figures,"polar_coherency_double.png"), label = "Coherency (weighted)",
678
- something2 = results_angle['Coherency'], label2 = "Coherency",dpi=dpi)
679
-
680
- plot_polar(results_angle['Angles Plotting'], results_angle['Mean Intensity'],
681
- path_png= os.path.join(figures,"polar_intensity.png"), label = "Mean Intensity",dpi=dpi)
776
+ something2 = results_angle['Coherency'], label2 = "Coherency",dpi=dpi, vmin=0,vmax=1)
682
777
 
683
778
  plot_polar(results_angle['Angles Plotting'], results_angle['Orientation (weighted by intensity and coherency)'],
684
- path_png= os.path.join(figures,"Orientation_weighted_polar.png"), label = "Orientation",dpi=dpi)
779
+ path_png= os.path.join(figures,"polar_orientation_double.png"), label = "Orientation (weighted)",
780
+ something2 = results_angle['Orientation'], label2 = "Orientation",dpi=dpi, vmin=-1,vmax=1)
685
781
 
686
- plot_polar(results_angle['Angles Plotting'], results_angle['Orientation'],
687
- path_png= os.path.join(figures,"Orientation_polar.png"), label = "Orientation",dpi=dpi)
688
- plt.close("all")
689
782
  # summarizing triple plot
690
783
  plot_triple(results_angle,results_total , path_png= os.path.join(figures,"Triple_plot.png") ,dpi=dpi)
691
-
692
- # quiver plots with center overlay
693
- quiv_coherency_center(vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
694
- center0=center_small[0],center1 = center_small[1],
695
- path_png= os.path.join(figures,"quiv_coherency_center.png"),dpi=dpi )
696
- plt.close("all")
697
- # image fiber + segmention
698
- plot_fiber_seg(fiber_image=normalize(im_fiber_n[edge:-edge,edge:-edge]) ,
699
- c0=center_small[0],c1=center_small[1],
700
- segmention=segmention["mask"][edge:-edge,edge:-edge],
701
- path_png=os.path.join(figures,"fiber_segemention.png"),dpi=dpi,scale=scale )
702
-
703
- # plot overlaywith fiber image
704
- plot_overlay(fiber_image=normalize(im_fiber_n[edge:-edge,edge:-edge]) ,
705
- c0=center_small[0],c1=center_small[1], vec0=min_evec[:,:,0],
706
- vec1=min_evec[:,:,1], coherency_map=ori, show_n=15,
707
- segmention=segmention["mask"][edge:-edge,edge:-edge],
708
- path_png=os.path.join(figures,"overlay.png"),dpi=dpi ,scale=scale)
709
-
710
- plot_overlay(fiber_image=normalize(im_fiber_n[edge:-edge,edge:-edge]) ,
711
- c0=center_small[0],c1=center_small[1], vec0=min_evec[:,:,0],
712
- vec1=min_evec[:,:,1], coherency_map=ori,show_n=10,
713
- segmention=segmention["mask"][edge:-edge,edge:-edge],
714
- path_png=os.path.join(figures,"overlay2.png"),dpi=dpi ,scale=scale)
715
- ##
716
-
717
-
784
+
785
+ if cell_list is not None:
786
+
787
+ # image fiber + segmention
788
+ plot_fiber_seg(fiber_image=normalize(im_fiber_n[edge:-edge,edge:-edge]) ,
789
+ c0=center_small[0],c1=center_small[1],
790
+ segmention=segmention["mask"][edge:-edge,edge:-edge],
791
+ path_png=os.path.join(figures,"fiber_celloutline.png"),dpi=dpi,scale=scale )
792
+ # plot overlaywith fiber image
793
+ plot_overlay(fiber_image=normalize(im_fiber_n[edge:-edge,edge:-edge]) ,
794
+ c0=center_small[0],c1=center_small[1], vec0=min_evec[:,:,0],
795
+ vec1=min_evec[:,:,1], coherency_map=ori, show_n=15,
796
+ segmention=segmention["mask"][edge:-edge,edge:-edge],
797
+ path_png=os.path.join(figures,"fiber_cell_structure.png"),dpi=dpi ,scale=scale)
798
+ else:
799
+ # plot overlaywith fiber image
800
+ plot_overlay(fiber_image=normalize(im_fiber_n[edge:-edge,edge:-edge]) ,
801
+ c0=center_small[0],c1=center_small[1], vec0=min_evec[:,:,0],
802
+ vec1=min_evec[:,:,1], coherency_map=ori, show_n=15,
803
+ segmention=None,
804
+ path_png=os.path.join(figures,"fiber_structure.png"),dpi=dpi ,scale=scale)
805
+
806
+
807
+
718
808
  plt.close("all")
719
809
  ### DISTANCE PLOTS
720
810
  # plot shells - deactived as it consumes a lot of time
@@ -726,12 +816,13 @@ def StuctureAnalysisMain(fiber_list,
726
816
 
727
817
  plot_distance(results_distance,string_plot = "Intensity Norm (individual)",
728
818
  path_png=os.path.join(figures,"Intensity_distance.png"),dpi=dpi)
729
- plt.close("all")
819
+
820
+
730
821
  # save raw cell image
731
822
  plot_cell(im_cell_n, path_png=os.path.join(figures,"cell-raw.png"), scale=scale, dpi=dpi)
823
+ plot_cell(normalize(im_fiber_n[edge:-edge,edge:-edge]), path_png=os.path.join(figures,"fiber-raw.png"), scale=scale, dpi=dpi)
732
824
 
733
- plt.close("all")
734
-
825
+ plt.close("all")
735
826
 
736
827
  return
737
828
 
@@ -758,10 +849,10 @@ def SummarizeResultsTotal(data, output_folder= None):
758
849
  'Overall weighted Oriantation (std all cells)': []}
759
850
 
760
851
  for i, path in enumerate(list_total):
761
- results_total_combined['Orientation (weighted by coherency)'].append(float(pd.read_excel(list_total[i])['Orientation (weighted by coherency)']))
762
- results_total_combined['Orientation (weighted by intensity and coherency)'].append(float(pd.read_excel(list_total[i])['Orientation (weighted by intensity and coherency)']))
763
- results_total_combined['Mean Angle (weighted by coherency)'].append(float(pd.read_excel(list_total[i])['Mean Angle (weighted by coherency)']))
764
- results_total_combined['Mean Angle (weighted by intensity and coherency)'].append(float(pd.read_excel(list_total[i])['Mean Angle (weighted by intensity and coherency)']))
852
+ results_total_combined['Orientation (weighted by coherency)'].append(float(pd.read_excel(list_total[i])['Orientation (weighted by coherency)'][0]))
853
+ results_total_combined['Orientation (weighted by intensity and coherency)'].append(float(pd.read_excel(list_total[i])['Orientation (weighted by intensity and coherency)'][0]))
854
+ results_total_combined['Mean Angle (weighted by coherency)'].append(float(pd.read_excel(list_total[i])['Mean Angle (weighted by coherency)'][0]))
855
+ results_total_combined['Mean Angle (weighted by intensity and coherency)'].append(float(pd.read_excel(list_total[i])['Mean Angle (weighted by intensity and coherency)'][0]))
765
856
  results_total_combined['Path'].append(str(list_total[i]))
766
857
 
767
858
  ovreall_orientation = np.nanmean(results_total_combined['Orientation (weighted by intensity and coherency)'])