CompactionAnalyzer 1.0.1__tar.gz → 1.0.3__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.
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer/CompactionFunctions.py +190 -130
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer/QtShortCuts.py +527 -58
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer/StructureTensor.py +10 -3
- compactionanalyzer-1.0.3/CompactionAnalyzer/__init__.py +7 -0
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer/plotting.py +51 -16
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer.egg-info/PKG-INFO +13 -6
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer.egg-info/SOURCES.txt +1 -1
- compactionanalyzer-1.0.3/CompactionAnalyzer.egg-info/requires.txt +10 -0
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/PKG-INFO +13 -6
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/README.md +61 -19
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/setup.py +7 -4
- CompactionAnalyzer-1.0.1/CompactionAnalyzer/__init__.py +0 -7
- CompactionAnalyzer-1.0.1/CompactionAnalyzer.egg-info/requires.txt +0 -5
- /CompactionAnalyzer-1.0.1/CompactionAnalyzer/GUI.py → /compactionanalyzer-1.0.3/CompactionAnalyzer/GUI_old_use_saenopy_instead.py +0 -0
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer/QExtendedGraphicsView.py +0 -0
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer/utilities.py +0 -0
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer.egg-info/dependency_links.txt +0 -0
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer.egg-info/top_level.txt +0 -0
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/LICENSE +0 -0
- {CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/setup.cfg +0 -0
{CompactionAnalyzer-1.0.1 → compactionanalyzer-1.0.3}/CompactionAnalyzer/CompactionFunctions.py
RENAMED
|
@@ -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
|
-
|
|
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):
|
|
@@ -204,10 +226,11 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
204
226
|
sigma_tensor = None , # sigma of applied gauss filter / window for structure tensor analysis in px
|
|
205
227
|
# should be in the order of the objects to analyze !!
|
|
206
228
|
# 7 um for collagen
|
|
207
|
-
edge =
|
|
229
|
+
edge = 15 , # Cutt of pixels at the edge since values at the border cannot be trusted
|
|
208
230
|
segmention_thres = 1.0 , # for cell segemetntion, thres 1 equals normal otsu threshold , user also can specify gaus1 + gaus2 in segmentation if needed
|
|
209
231
|
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
232
|
max_dist = None, # optional: specify the maximal distance around cell center for analysis (in px)
|
|
233
|
+
min_dist = None, # optional: specify the minimals distance around cell center for analysis (in px)
|
|
211
234
|
regional_max_correction = True,# background correction using regional maxima approach
|
|
212
235
|
show_segmentation = False , # display the segmentation output
|
|
213
236
|
sigma_first_blur = 0.5 , # slight first bluring of whole image before appplying the structure tensor
|
|
@@ -219,12 +242,14 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
219
242
|
SaveNumpy = False , # saves numpy arrays for later analysis - can create large data files
|
|
220
243
|
norm1=1,norm2 = 99 , # contrast spreading for input images between norm1- and norm2-percentile; values below norm1-percentile are set to zero and
|
|
221
244
|
# values above norm2-percentile are set to 1
|
|
245
|
+
### use norm1= 0,norm2 = 100 if no contras enhancement desired
|
|
222
246
|
seg_invert=False, # if segmentation is inverted dark objects are detected inseated of bright objects
|
|
223
247
|
seg_iter = 1, # number of repetitions of binary closing, dilation and filling holes steps
|
|
224
248
|
segmention_method="otsu", # use "otsu", "entropy" or "yen" as segmentation method
|
|
225
249
|
segmention_min_area = 1000, # small bjects below this px-area are removed during cell segmentation
|
|
226
250
|
load_segmentation = False, # if True enter the path of the segementation.npy - file in path_seg
|
|
227
|
-
path_seg = None
|
|
251
|
+
path_seg = None, # to load a mask
|
|
252
|
+
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
|
|
228
253
|
"""
|
|
229
254
|
Main analysis
|
|
230
255
|
|
|
@@ -268,7 +293,7 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
268
293
|
'SaveNumpy': [SaveNumpy], 'norm1': [norm1], 'norm2': [norm2],
|
|
269
294
|
'seg_invert': [seg_invert], 'seg_iter': [seg_iter], 'segmention_method': [segmention_method],
|
|
270
295
|
'load_segmentation': [load_segmentation], 'path_seg': [path_seg],
|
|
271
|
-
'max_dist': [max_dist]
|
|
296
|
+
'max_dist': [max_dist], 'min_dist': [min_dist]
|
|
272
297
|
|
|
273
298
|
},
|
|
274
299
|
'Data' : {'fiber_list': [fiber_list], 'cell_list': [cell_list], 'out_list': [out_list]}
|
|
@@ -278,20 +303,20 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
278
303
|
|
|
279
304
|
|
|
280
305
|
# load images
|
|
281
|
-
im_cell = imageio.imread(cell_list[n]) #color.rgb2gray(..)
|
|
282
|
-
im_fiber = imageio.imread(fiber_list[n]) #color.rgb2gray()
|
|
306
|
+
im_cell = imageio.v2.imread(cell_list[n]) #color.rgb2gray(..)
|
|
307
|
+
im_fiber = imageio.v2.imread(fiber_list[n]) #color.rgb2gray()
|
|
283
308
|
|
|
284
309
|
## if 3 channels convert to grey
|
|
285
310
|
if len(im_cell.shape) == 3 :
|
|
286
311
|
im_cell = color.rgb2gray(im_cell)
|
|
287
312
|
if len(im_fiber.shape) == 3 :
|
|
288
313
|
im_fiber = color.rgb2gray(im_fiber)
|
|
289
|
-
|
|
314
|
+
|
|
290
315
|
# # applying normalizing/ contrast spreading
|
|
291
316
|
im_cell_n = normalize(im_cell, norm1, norm2)
|
|
292
317
|
im_fiber_n = normalize(im_fiber, norm1, norm2)
|
|
293
318
|
im_fiber_g = gaussian(im_fiber_n, sigma=sigma_first_blur) # blur fiber image slightly (test with local gauss - similar)
|
|
294
|
-
|
|
319
|
+
|
|
295
320
|
|
|
296
321
|
# segment cell (either manual or automatically)
|
|
297
322
|
if manual_segmention==True:
|
|
@@ -308,20 +333,30 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
308
333
|
# center of the new cropped image (to avoid edge effects)
|
|
309
334
|
center_small = (segmention["centroid"][0]-edge,segmention["centroid"][1]-edge)
|
|
310
335
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
336
|
+
|
|
337
|
+
## do not set cell area to nan and but only use center from segmention if activaed
|
|
338
|
+
if ignore_cell_outline is True:
|
|
339
|
+
im_fiber_g_forstructure = im_fiber_g.copy()
|
|
340
|
+
else:
|
|
341
|
+
# set segmention mask to nan to avoid effects within cell (maybe not needed if signal below cell makes sense)
|
|
342
|
+
im_fiber_g_forstructure = im_fiber_g.copy()
|
|
343
|
+
im_fiber_g_forstructure[segmention["mask"]] = np.nan
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
315
347
|
"""
|
|
316
348
|
Structure tensor
|
|
317
349
|
"""
|
|
318
350
|
# Structure Tensor Orientation
|
|
319
351
|
# get structure tensor
|
|
320
352
|
ori, max_evec, min_evec, max_eval, min_eval = analyze_local(im_fiber_g_forstructure, sigma=sigma_tensor, size=0, filter_type="gaussian")
|
|
353
|
+
|
|
321
354
|
# cut off edges as specified
|
|
322
355
|
if edge != 0:
|
|
323
356
|
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], \
|
|
324
357
|
max_eval[edge:-edge,edge:-edge], min_eval[edge:-edge,edge:-edge]
|
|
358
|
+
|
|
359
|
+
|
|
325
360
|
"""
|
|
326
361
|
coordinates
|
|
327
362
|
"""
|
|
@@ -334,31 +369,32 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
334
369
|
dx_norm = (dx/distance)
|
|
335
370
|
dy_norm = (dy/distance)
|
|
336
371
|
dist_surface = distance_transform_edt(~segmention["mask"])[edge:-edge,edge:-edge] # dist to surface
|
|
337
|
-
|
|
338
|
-
|
|
372
|
+
# calculate an angle without the deviation/reference to the cell position
|
|
373
|
+
angle_no_reference = np.arctan2(min_evec[:,:,0],min_evec[:,:,1])*360/(2*np.pi)
|
|
374
|
+
|
|
375
|
+
|
|
339
376
|
"""
|
|
340
377
|
total image analysis
|
|
341
378
|
"""
|
|
342
|
-
# Angular deviation from orietation to center vector
|
|
379
|
+
# Angular deviation from orietation to center vector (projection to only have positive deviation angle values since negative/positive deviation does not matter here)
|
|
343
380
|
angle_dev = np.arccos(np.abs(dx_norm * min_evec[:,:,0] + dy_norm*min_evec[:,:,1])) * 360/(2*np.pi)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
381
|
+
## compute the orientation
|
|
382
|
+
orientation_dev = 1 - (2 * np.arccos(np.abs(dx_norm * min_evec[:,:,0] + dy_norm*min_evec[:,:,1]))/ (0.5* np.pi))
|
|
383
|
+
|
|
384
|
+
|
|
349
385
|
### set values to nan if max distance is specified
|
|
350
386
|
## for following analysis then only orientation within a certtain distance to the cell are used
|
|
351
387
|
if max_dist:
|
|
352
|
-
angle_dev[distance
|
|
353
|
-
ori[distance
|
|
354
|
-
angle[distance
|
|
388
|
+
angle_dev[distance>max_dist] = np.nan
|
|
389
|
+
ori[distance>max_dist] = np.nan
|
|
390
|
+
angle[distance>max_dist] = np.nan # also for angular evaluation
|
|
355
391
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
392
|
+
if min_dist:
|
|
393
|
+
angle_dev[distance<min_dist] = np.nan
|
|
394
|
+
ori[distance<min_dist] = np.nan
|
|
395
|
+
angle[distance<max_dist] = np.nan # also for angular evaluation
|
|
396
|
+
|
|
397
|
+
|
|
362
398
|
# weighting by coherence and image intensity
|
|
363
399
|
im_fiber_g = im_fiber_g[edge:-edge,edge:-edge]
|
|
364
400
|
# could also use non filtered image
|
|
@@ -366,14 +402,18 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
366
402
|
# use a threshold in the intensity image// only coherence and orientation vectors
|
|
367
403
|
# corresponding to pixels in the intesity iamage above a threshold are considered.
|
|
368
404
|
weight_image = gaussian(im_fiber_g,sigma=15)
|
|
405
|
+
|
|
406
|
+
# construct weighted array so that the mean value of these arrays later
|
|
407
|
+
# result in the weighted average of these
|
|
408
|
+
# weight by coherency
|
|
409
|
+
angle_dev_weighted = (angle_dev * ori) / np.nanmean(ori)
|
|
410
|
+
orientation_dev_weighted = (orientation_dev * ori) / np.nanmean(ori)
|
|
411
|
+
# weight by coherency & intensity
|
|
369
412
|
angle_dev_weighted2 = (angle_dev_weighted *weight_image) / np.nanmean(weight_image)
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
# also weighting the coherency like this
|
|
413
|
+
orientation_dev_weighted2 = (orientation_dev *weight_image*ori) / np.nanmean(weight_image*ori)
|
|
414
|
+
# weighting coherency by intensity
|
|
374
415
|
ori_weight2 = (ori * weight_image) / np.nanmean(weight_image)
|
|
375
|
-
|
|
376
|
-
|
|
416
|
+
|
|
377
417
|
# GRADIENT towards center
|
|
378
418
|
grad_y = np.gradient(im_fiber_g, axis=0)
|
|
379
419
|
grad_x = np.gradient(im_fiber_g, axis=1)
|
|
@@ -394,9 +434,7 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
394
434
|
alpha_dev_total1 = np.nanmean(angle_dev[(~segmention["mask"][edge:-edge,edge:-edge])])
|
|
395
435
|
alpha_dev_total2 = np.nanmean(angle_dev_weighted[(~segmention["mask"][edge:-edge, edge:-edge])])
|
|
396
436
|
alpha_dev_total3 = np.nanmean(angle_dev_weighted2[(~segmention["mask"][edge:-edge, edge:-edge])])
|
|
397
|
-
|
|
398
|
-
# cos_dev_total2 = np.nanmean(np.cos(2*angle_dev_weighted[(~segmention["mask"][edge:-edge, edge:-edge])]*np.pi/180))
|
|
399
|
-
# cos_dev_total3 = np.nanmean(np.cos(2*angle_dev_weighted2[(~segmention["mask"][edge:-edge, edge:-edge])]*np.pi/180))
|
|
437
|
+
|
|
400
438
|
cos_dev_total1 = np.nanmean(orientation_dev[(~segmention["mask"][edge:-edge,edge:-edge]) ])
|
|
401
439
|
cos_dev_total2 = np.nanmean(orientation_dev_weighted[(~segmention["mask"][edge:-edge,edge:-edge]) ])
|
|
402
440
|
cos_dev_total3 = np.nanmean(orientation_dev_weighted2[(~segmention["mask"][edge:-edge,edge:-edge]) ])
|
|
@@ -563,59 +601,32 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
563
601
|
excel_distance = pd.DataFrame.from_dict(results_distance)
|
|
564
602
|
excel_distance.to_excel(os.path.join(out_list[n],"results_distance.xlsx"))
|
|
565
603
|
|
|
566
|
-
|
|
567
|
-
# Halflife values - Leave for now..
|
|
568
|
-
# # Calculate value where ntensity drops 25%
|
|
569
|
-
# distintdrop = np.abs(np.array(results_distance['Intensity Norm (individual)'])-0.75)
|
|
570
|
-
# # distance where int drops to 75%
|
|
571
|
-
# halflife_int = midofshells[np.where(distintdrop == np.nanmin(distintdrop))[1]]
|
|
572
|
-
# # if decrease is not within range (minimum equals last value) then set to nan
|
|
573
|
-
# if halflife_int == midofshells[-1]:
|
|
574
|
-
# halflife_int = np.nan
|
|
575
|
-
# # # Calculate value where orientation drops to 75% within maxorientation(min) to 45° (random) range
|
|
576
|
-
# # difference to 45 degree instead of min-max range
|
|
577
|
-
# # calculate halflife of maximal orientation over distance
|
|
578
|
-
# # difference to 45 degree for all
|
|
579
|
-
# diffdist = np.array(dist_angle_individ)-45
|
|
580
|
-
# # maximal orientation
|
|
581
|
-
# diffmax = np.nanmin(diffdist)
|
|
582
|
-
# diffmax_pos = np.where(diffmax==diffdist)[0][0]
|
|
583
|
-
# # difference angle drops to 75%
|
|
584
|
-
# diff2 = np.abs(diffdist-(0.75*diffmax))
|
|
585
|
-
# diff2[:diffmax_pos] = np.nan # only look at distances on the right side /further out
|
|
586
|
-
# halflife_ori = midofshells[np.where(diff2 == np.nanmin(diff2))]
|
|
587
|
-
# # if decrease is not within range (minimum equals last value) then set to nan
|
|
588
|
-
# if halflife_ori == midofshells[-1]:
|
|
589
|
-
# halflife_ori = np.nan
|
|
590
|
-
# try:
|
|
591
|
-
# np.savetxt(os.path.join(out_list[n],"meanangle_within10shells.txt"), [dist_angle_accum[9]])
|
|
592
|
-
# except:
|
|
593
|
-
# pass
|
|
604
|
+
|
|
594
605
|
|
|
595
606
|
if SaveNumpy:
|
|
596
607
|
#create output folder if not existing
|
|
597
|
-
numpy_out = os.path.join(out_list[n],
|
|
608
|
+
numpy_out = os.path.join(out_list[n], "NumpyArrays" )
|
|
609
|
+
print (numpy_out)
|
|
598
610
|
if not os.path.exists(numpy_out):
|
|
599
611
|
os.makedirs(numpy_out)
|
|
600
612
|
|
|
601
613
|
np.save(os.path.join(numpy_out, "segmention.npy" ),segmention)
|
|
602
|
-
np.save(os.path.join(numpy_out, "
|
|
603
|
-
np.save(os.path.join(numpy_out, "AngleMap(weight_int).npy" ),angle_dev_weighted)
|
|
604
|
-
np.save(os.path.join(numpy_out, "
|
|
614
|
+
np.save(os.path.join(numpy_out, "AngleDeviationMap.npy" ),angle_dev )
|
|
615
|
+
#np.save(os.path.join(numpy_out, "AngleMap(weight_int).npy" ),angle_dev_weighted)
|
|
616
|
+
np.save(os.path.join(numpy_out, "AngleDeviationMap(weight_int_coh).npy"),angle_dev_weighted2 )
|
|
617
|
+
np.save(os.path.join(numpy_out, "AngleMap_NoReference.npy"), angle_no_reference )
|
|
605
618
|
np.save(os.path.join(numpy_out, "OrientationMap.npy" ),orientation_dev )
|
|
606
|
-
np.save(os.path.join(numpy_out, "OrientationMap_weight_int.npy" ),orientation_dev_weighted)
|
|
619
|
+
#np.save(os.path.join(numpy_out, "OrientationMap_weight_int.npy" ),orientation_dev_weighted)
|
|
607
620
|
np.save(os.path.join(numpy_out, "OrientationMap_weight_intcoh.npy" ),orientation_dev_weighted2 )
|
|
608
621
|
np.save(os.path.join(numpy_out, "FiberImageCrop.npy" ),normalize(im_fiber_n[edge:-edge,edge:-edge]) )
|
|
609
622
|
np.save(os.path.join(numpy_out, "CoherencyMap.npy" ),ori )
|
|
610
|
-
np.save(os.path.join(numpy_out, "CoherencyMap(weighted_int).npy" ),ori_weight2)
|
|
623
|
+
#np.save(os.path.join(numpy_out, "CoherencyMap(weighted_int).npy" ),ori_weight2)
|
|
611
624
|
np.save(os.path.join(numpy_out, "Vector_min_ax0.npy"),min_evec[:,:,0])
|
|
612
625
|
np.save(os.path.join(numpy_out, "Vector_min_ax1.npy"),min_evec[:,:,1])
|
|
613
|
-
np.save(os.path.join(numpy_out, "mask_surface_shells.npy"),mask_shells['Mask_shell'])
|
|
614
|
-
np.save(os.path.join(numpy_out, "mask_spherical_shells.npy"),mask_shells['Mask_shell_center'])
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
626
|
+
#np.save(os.path.join(numpy_out, "mask_surface_shells.npy"),mask_shells['Mask_shell'])
|
|
627
|
+
#np.save(os.path.join(numpy_out, "mask_spherical_shells.npy"),mask_shells['Mask_shell_center'])
|
|
628
|
+
|
|
629
|
+
|
|
619
630
|
"""
|
|
620
631
|
Plott results
|
|
621
632
|
"""
|
|
@@ -623,55 +634,103 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
623
634
|
if plotting:
|
|
624
635
|
#create output folder if not existing
|
|
625
636
|
figures = os.path.join(out_list[n],"Figures")
|
|
637
|
+
print (figures)
|
|
626
638
|
if not os.path.exists(figures):
|
|
627
639
|
os.makedirs(figures)
|
|
628
|
-
|
|
640
|
+
|
|
641
|
+
plot_angle_dev(angle_map = orientation_dev, vmin=-1,vmax=1,
|
|
642
|
+
vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
|
|
643
|
+
path_png= os.path.join(figures,"Orientation.png"),label="Orientation",dpi=dpi,cmap="coolwarm")
|
|
629
644
|
# plot orientation and angle deviation maps together with orientation structure
|
|
630
|
-
plot_angle_dev(angle_map = angle_dev,
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
#
|
|
644
|
-
|
|
645
|
-
plot_coherency(
|
|
646
|
-
|
|
647
|
-
|
|
645
|
+
# plot_angle_dev(angle_map = angle_dev, vmin=0,vmax=90,
|
|
646
|
+
# vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
|
|
647
|
+
# path_png= os.path.join(figures,"Angle_deviation.png"),label="Angle Deviation",dpi=dpi,cmap="viridis_r")
|
|
648
|
+
|
|
649
|
+
# # do not show the weighted ones here, as only the mean has the same range again and here angles can be smaller/large
|
|
650
|
+
# plot_angle_dev(angle_map = angle_dev_weighted2,
|
|
651
|
+
# vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
|
|
652
|
+
# path_png= os.path.join(figures,"Angle_deviation_weighted.png"),label="Angle Deviation",dpi=dpi,cmap="viridis_r")
|
|
653
|
+
# plot_angle_dev(angle_map = orientation_dev_weighted2 ,
|
|
654
|
+
# vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
|
|
655
|
+
# path_png= os.path.join(figures,"Orientation_weighted.png"),label="Orientation",dpi=dpi,cmap="viridis")
|
|
656
|
+
|
|
657
|
+
# # pure coherency and pure orientation
|
|
658
|
+
# plot_coherency(ori,path_png= os.path.join(figures,"coherency_noquiver.png"),
|
|
659
|
+
# label="Coherency",vmin=0,vmax=1,cmap="turbo",dpi=dpi)
|
|
660
|
+
# plot_coherency(orientation_dev,
|
|
661
|
+
# path_png= os.path.join(figures,"Orientation_noquiver.png"),
|
|
662
|
+
# label="Orientation",vmin=-1,vmax=1,cmap="coolwarm",dpi=dpi)
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
### more fancy overlay plot of cell & fiber & orientation (notweighted)
|
|
666
|
+
plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
|
|
667
|
+
im_cell_n[edge:-edge,edge:-edge],
|
|
668
|
+
orientation_dev, cmap_angle="coolwarm",
|
|
669
|
+
path_png= os.path.join(figures,"Orientation_overlay.png"),
|
|
670
|
+
label="Orientation",dpi=dpi,
|
|
671
|
+
# ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
|
|
672
|
+
# cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
|
|
673
|
+
omin=-1, omax=1,scale=scale)
|
|
674
|
+
|
|
675
|
+
plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
|
|
676
|
+
im_cell_n[edge:-edge,edge:-edge],
|
|
677
|
+
ori, cmap_angle="turbo",
|
|
678
|
+
path_png= os.path.join(figures,"Coherency_overlay.png"),
|
|
679
|
+
label="Coherency",dpi=dpi,
|
|
680
|
+
# ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
|
|
681
|
+
# cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
|
|
682
|
+
omin=0, omax=1,scale=scale)
|
|
683
|
+
|
|
684
|
+
plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
|
|
685
|
+
im_cell_n[edge:-edge,edge:-edge],
|
|
686
|
+
angle_dev, cmap_angle="viridis_r",
|
|
687
|
+
path_png= os.path.join(figures,"Angle_Deviation_overlay.png"),
|
|
688
|
+
label="Angle Deviation",dpi=dpi,
|
|
689
|
+
# ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
|
|
690
|
+
# cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
|
|
691
|
+
omin=0, omax=90,scale=scale)
|
|
692
|
+
|
|
693
|
+
plot_fancy_overlay(im_fiber_n[edge:-edge,edge:-edge],
|
|
694
|
+
im_cell_n[edge:-edge,edge:-edge],
|
|
695
|
+
angle_no_reference, cmap_angle="gist_rainbow",
|
|
696
|
+
path_png= os.path.join(figures,"Angle_NoReference_overlay.png"),
|
|
697
|
+
label="Angle (no reference)",dpi=dpi,
|
|
698
|
+
# ,cmap_cell="Greys_r",cmap_fiber="Greys_r", ### use default values here
|
|
699
|
+
# cmap_angle="viridis", alpha_ori =0.8, alpha_cell = 0.4, alpha_fiber = 0.4,
|
|
700
|
+
omin=-180, omax=180,
|
|
701
|
+
scale=scale)
|
|
702
|
+
|
|
703
|
+
|
|
648
704
|
plt.close("all")
|
|
649
|
-
|
|
650
|
-
plot_polar(results_angle['Angles Plotting'], results_angle['Coherency (weighted by intensity)'],
|
|
651
|
-
path_png= os.path.join(figures,"polar_coherency_weighted.png"), label = "Coherency (weighted)",dpi=dpi)
|
|
705
|
+
|
|
652
706
|
|
|
653
|
-
|
|
707
|
+
# Polar plots
|
|
654
708
|
plot_polar(results_angle['Angles Plotting'], results_angle['Coherency (weighted by intensity)'],
|
|
655
709
|
path_png= os.path.join(figures,"polar_coherency_double.png"), label = "Coherency (weighted)",
|
|
656
|
-
something2 = results_angle['Coherency'], label2 = "Coherency",dpi=dpi)
|
|
657
|
-
|
|
658
|
-
plot_polar(results_angle['Angles Plotting'], results_angle['Mean Intensity'],
|
|
659
|
-
path_png= os.path.join(figures,"polar_intensity.png"), label = "Mean Intensity",dpi=dpi)
|
|
710
|
+
something2 = results_angle['Coherency'], label2 = "Coherency",dpi=dpi, vmin=0,vmax=1)
|
|
660
711
|
|
|
661
712
|
plot_polar(results_angle['Angles Plotting'], results_angle['Orientation (weighted by intensity and coherency)'],
|
|
662
|
-
|
|
713
|
+
path_png= os.path.join(figures,"polar_orientation_double.png"), label = "Orientation (weighted)",
|
|
714
|
+
something2 = results_angle['Orientation'], label2 = "Orientation",dpi=dpi, vmin=-1,vmax=1)
|
|
663
715
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
716
|
+
# plot_polar(results_angle['Angles Plotting'], results_angle['Coherency (weighted by intensity)'],
|
|
717
|
+
# path_png= os.path.join(figures,"polar_coherency_weighted.png"), label = "Coherency (weighted)",dpi=dpi)
|
|
718
|
+
|
|
719
|
+
# plot_polar(results_angle['Angles Plotting'], results_angle['Mean Intensity'],
|
|
720
|
+
# path_png= os.path.join(figures,"polar_intensity.png"), label = "Mean Intensity",dpi=dpi)
|
|
721
|
+
|
|
722
|
+
# plot_polar(results_angle['Angles Plotting'], results_angle['Orientation (weighted by intensity and coherency)'],
|
|
723
|
+
# path_png= os.path.join(figures,"Orientation_weighted_polar.png"), label = "Orientation",dpi=dpi)
|
|
724
|
+
|
|
725
|
+
# plot_polar(results_angle['Angles Plotting'], results_angle['Orientation'],
|
|
726
|
+
# path_png= os.path.join(figures,"Orientation_polar.png"), label = "Orientation",dpi=dpi)
|
|
727
|
+
# quiver plots with center overlay
|
|
728
|
+
# quiv_coherency_center(vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
|
|
729
|
+
# center0=center_small[0],center1 = center_small[1],
|
|
730
|
+
# path_png= os.path.join(figures,"quiv_coherency_center.png"),dpi=dpi )
|
|
731
|
+
|
|
667
732
|
# summarizing triple plot
|
|
668
733
|
plot_triple(results_angle,results_total , path_png= os.path.join(figures,"Triple_plot.png") ,dpi=dpi)
|
|
669
|
-
|
|
670
|
-
# quiver plots with center overlay
|
|
671
|
-
quiv_coherency_center(vec0=min_evec[:,:,0] ,vec1=min_evec[:,:,1] ,coherency_map=ori,
|
|
672
|
-
center0=center_small[0],center1 = center_small[1],
|
|
673
|
-
path_png= os.path.join(figures,"quiv_coherency_center.png"),dpi=dpi )
|
|
674
|
-
plt.close("all")
|
|
675
734
|
# image fiber + segmention
|
|
676
735
|
plot_fiber_seg(fiber_image=normalize(im_fiber_n[edge:-edge,edge:-edge]) ,
|
|
677
736
|
c0=center_small[0],c1=center_small[1],
|
|
@@ -685,11 +744,12 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
685
744
|
segmention=segmention["mask"][edge:-edge,edge:-edge],
|
|
686
745
|
path_png=os.path.join(figures,"overlay.png"),dpi=dpi ,scale=scale)
|
|
687
746
|
|
|
688
|
-
plot_overlay(fiber_image=normalize(im_fiber_n[edge:-edge,edge:-edge]) ,
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
747
|
+
# plot_overlay(fiber_image=normalize(im_fiber_n[edge:-edge,edge:-edge]) ,
|
|
748
|
+
# c0=center_small[0],c1=center_small[1], vec0=min_evec[:,:,0],
|
|
749
|
+
# vec1=min_evec[:,:,1], coherency_map=ori,show_n=10,
|
|
750
|
+
# segmention=segmention["mask"][edge:-edge,edge:-edge],
|
|
751
|
+
# path_png=os.path.join(figures,"overlay2.png"),dpi=dpi ,scale=scale)
|
|
752
|
+
|
|
693
753
|
plt.close("all")
|
|
694
754
|
### DISTANCE PLOTS
|
|
695
755
|
# plot shells - deactived as it consumes a lot of time
|
|
@@ -701,12 +761,12 @@ def StuctureAnalysisMain(fiber_list,
|
|
|
701
761
|
|
|
702
762
|
plot_distance(results_distance,string_plot = "Intensity Norm (individual)",
|
|
703
763
|
path_png=os.path.join(figures,"Intensity_distance.png"),dpi=dpi)
|
|
704
|
-
|
|
764
|
+
|
|
765
|
+
|
|
705
766
|
# save raw cell image
|
|
706
767
|
plot_cell(im_cell_n, path_png=os.path.join(figures,"cell-raw.png"), scale=scale, dpi=dpi)
|
|
707
768
|
|
|
708
|
-
plt.close("all")
|
|
709
|
-
|
|
769
|
+
plt.close("all")
|
|
710
770
|
|
|
711
771
|
return
|
|
712
772
|
|
|
@@ -733,10 +793,10 @@ def SummarizeResultsTotal(data, output_folder= None):
|
|
|
733
793
|
'Overall weighted Oriantation (std all cells)': []}
|
|
734
794
|
|
|
735
795
|
for i, path in enumerate(list_total):
|
|
736
|
-
results_total_combined['Orientation (weighted by coherency)'].append(float(pd.read_excel(list_total[i])['Orientation (weighted by coherency)']))
|
|
737
|
-
results_total_combined['Orientation (weighted by intensity and coherency)'].append(float(pd.read_excel(list_total[i])['Orientation (weighted by intensity and coherency)']))
|
|
738
|
-
results_total_combined['Mean Angle (weighted by coherency)'].append(float(pd.read_excel(list_total[i])['Mean Angle (weighted by coherency)']))
|
|
739
|
-
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)']))
|
|
796
|
+
results_total_combined['Orientation (weighted by coherency)'].append(float(pd.read_excel(list_total[i])['Orientation (weighted by coherency)'][0]))
|
|
797
|
+
results_total_combined['Orientation (weighted by intensity and coherency)'].append(float(pd.read_excel(list_total[i])['Orientation (weighted by intensity and coherency)'][0]))
|
|
798
|
+
results_total_combined['Mean Angle (weighted by coherency)'].append(float(pd.read_excel(list_total[i])['Mean Angle (weighted by coherency)'][0]))
|
|
799
|
+
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]))
|
|
740
800
|
results_total_combined['Path'].append(str(list_total[i]))
|
|
741
801
|
|
|
742
802
|
ovreall_orientation = np.nanmean(results_total_combined['Orientation (weighted by intensity and coherency)'])
|