Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 8105237d authored by NADAL Morgane's avatar NADAL Morgane
Browse files

bugs correction

parent 1c3e0601
No related branches found
No related tags found
No related merge requests found
......@@ -192,6 +192,7 @@ class extension_t(glial_cmp_t):
result = image.copy()
if (low is not None) and (high is not None):
result = __HysterisisImage__(result, low, high)
# np_.save("D:\\MorganeNadal\\img512enhanced_norm_hyst_2.npy", result)
if selem is not None:
result = __MorphologicalCleaning__(result, selem)
......
......@@ -140,7 +140,7 @@ def GetNodesCoordinates(node_coord: Tuple[str, ...]) -> list:
for node in range(len(node_coord)):
coord_node = coord[node]
pattern = '\d+'
pattern = r"\d+"
coord_node = re_.findall(pattern, coord_node)
coor = []
for i in range(3):
......@@ -151,7 +151,7 @@ def GetNodesCoordinates(node_coord: Tuple[str, ...]) -> list:
return coord
def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int, max_range: float, hist_min_length: float, scale_map: array_t, decimals: int = 4):
def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, bins_length:array_t, bins_curvature:array_t, scale_map: array_t, decimals: int = 4):
"""
Extract the features from somas and graphs.
Returns a pandas dataframe.
......@@ -200,6 +200,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
"median_curvature",
"std_curvature",
"entropy_curvature",
"hist_curvature",
"min_torsion",
"max_torsion",
"mean_torsion",
......@@ -233,6 +234,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
"median_curvature_P",
"std_curvature_P",
"entropy_curvature_P",
"hist_curvature_P",
"min_torsion_P",
"max_torsion_P",
"mean_torsion_P",
......@@ -266,6 +268,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
"median_curvature_S",
"std_curvature_S",
"entropy_curvature_S",
"hist_curvature_S",
"min_torsion_S",
"max_torsion_S",
"mean_torsion_S",
......@@ -320,7 +323,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
total_ext_length = in_.ToMicron(soma.skl_graph.length, size_voxel_in_micron, decimals=decimals)
#
# Lengths histogram
hist_lengths = np_.histogram(ext_lengths, bins=number_of_bins, range=(hist_min_length, max_range))[0]
hist_lengths = np_.histogram(ext_lengths, bins_length)[0]
#
# min, mean, median, max and standard deviation of the ALL extensions
min_length = in_.ToMicron(soma.skl_graph.min_length, size_voxel_in_micron, decimals=decimals)
......@@ -360,13 +363,14 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature = np_.median(curvatures)
std_curvature = np_.std(curvatures)
entropy_curvature = st_.entropy(curvatures)
hist_curvature = np_.histogram(curvatures, bins_curvature)[0]
#
min_torsion = min(torsions)
max_torsion = max(torsions)
mean_torsion = np_.mean(torsions)
median_torsion = np_.median(torsions)
std_torsion = np_.std(torsions)
if any(torsions > 0):
if any(torsions) > 0:
entropy_torsion = st_.entropy(torsions)
else:
entropy_torsion = 0
......@@ -386,7 +390,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
total_ext_length_P = sum(ext_lengths_P)
#
# Lengths histogram
hist_lengths_P = np_.histogram(ext_lengths_P, bins=number_of_bins, range=(hist_min_length, max_range))[0]
hist_lengths_P = np_.histogram(ext_lengths_P, bins_length)[0]
#
# min, mean, median, max and standard deviation of the PRIMARY extensions
min_length_P = min(ext_lengths_P)
......@@ -424,13 +428,14 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature_P = np_.median(curvatures_P)
std_curvature_P = np_.std(curvatures_P)
entropy_curvature_P = st_.entropy(curvatures_P)
hist_curvature_P = np_.histogram(curvatures_P, bins_curvature)[0]
#
min_torsion_P = min(torsions_P)
max_torsion_P = max(torsions_P)
mean_torsion_P = np_.mean(torsions_P)
median_torsion_P = np_.median(torsions_P)
std_torsion_P = np_.std(torsions_P)
if any(torsions_P > 0):
if any(torsions_P) > 0:
entropy_torsion_P = st_.entropy(torsions_P)
else:
entropy_torsion_P = 0
......@@ -458,7 +463,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
total_ext_length_S = sum(ext_lengths_S)
#
# Lengths histogram
hist_lengths_S = np_.histogram(ext_lengths_S, bins=number_of_bins, range=(hist_min_length, max_range))[0]
hist_lengths_S = np_.histogram(ext_lengths_S, bins_length)[0]
#
# min, mean, median, max and standard deviation of the PRIMARY extensions
min_length_S = min(ext_lengths_S)
......@@ -494,13 +499,14 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature_S = np_.median(curvatures_S)
std_curvature_S = np_.std(curvatures_S)
entropy_curvature_S = st_.entropy(curvatures_S)
hist_curvature_S = np_.histogram(ext_lengths_S, bins_curvature)[0]
#
min_torsion_S = min(torsions_S)
max_torsion_S = max(torsions_S)
mean_torsion_S = np_.mean(torsions_S)
median_torsion_S = np_.median(torsions_S)
std_torsion_S = np_.std(torsions_S)
if any(torsions_S > 0):
if any(torsions_S) > 0:
entropy_torsion_S = st_.entropy(torsions_S)
else:
entropy_torsion_S = 0
......@@ -551,6 +557,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature_S = -1
std_curvature_S = 0
entropy_curvature_S = 0
hist_curvature_S = 0
#
min_torsion_S = -1
max_torsion_S = -1
......@@ -592,6 +599,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature = -1
std_curvature = 0
entropy_curvature = 0
hist_curvature = 0
min_torsion = -1
max_torsion= -1
mean_torsion = -1
......@@ -625,6 +633,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature_P = -1
std_curvature_P = 0
entropy_curvature_P = 0
hist_curvature_P = 0
min_torsion_P = -1
max_torsion_P = -1
mean_torsion_P = -1
......@@ -658,6 +667,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature_S = -1
std_curvature_S = 0
entropy_curvature_S = 0
hist_curvature_S = 0
min_torsion_S = -1
max_torsion_S = -1
mean_torsion_S = -1
......@@ -714,6 +724,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature,
std_curvature,
entropy_curvature,
hist_curvature,
min_torsion,
max_torsion,
mean_torsion,
......@@ -747,6 +758,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature_P,
std_curvature_P,
entropy_curvature_P,
hist_curvature_P,
min_torsion_P,
max_torsion_P,
mean_torsion_P,
......@@ -780,6 +792,7 @@ def ExtractFeaturesInDF(somas, size_voxel_in_micron: list, number_of_bins: int,
median_curvature_S,
std_curvature_S,
entropy_curvature_S,
hist_curvature_S,
min_torsion_S,
max_torsion_S,
mean_torsion_S,
......
......@@ -96,8 +96,11 @@ frangi_c = None
bright_on_dark = None
method = None
hist_min_length = None
hist_step = None
number_of_bins = None
hist_step_length = None
number_of_bins_length = None
hist_min_curvature = None
hist_step_curvature = None
number_of_bins_curvature = None
with_plot = None
in_parallel = None
......@@ -126,12 +129,14 @@ image = in_.ImageVerification(image, channel)
image = image[:, 512:, 512:] # 512 # 562 # Just for development
img_shape = image.shape
# np_.save("D:\\MorganeNadal\\img512.npy", image)
#
print(f"IMAGE: s.{img_shape} t.{image.dtype} m.{image.min()} M.{image.max()}")
# Intensity relative normalization (between 0 and 1).
image_for_soma = in_.IntensityNormalizedImage(image)
image_for_ext = in_.IntensityNormalizedImage(image)
# np_.save("D:\\MorganeNadal\\img512norm.npy", image_for_ext)
print(f"NRM-IMG: t.{image_for_soma.dtype} m.{image_for_soma.min():.2f} M.{image_for_soma.max():.2f}")
......@@ -208,10 +213,13 @@ enhanced_ext, ext_scales = extension_t.EnhancedForDetection(
method,
in_parallel=in_parallel)
# np_.save("D:\\MorganeNadal\\img512enhanced.npy", enhanced_ext)
elapsed_time = tm_.gmtime(tm_.time() - start_time)
print(f"Elapsed Time={tm_.strftime('%Hh %Mm %Ss', elapsed_time)}\n")
enhanced_ext = in_.IntensityNormalizedImage(enhanced_ext)
# np_.save("D:\\MorganeNadal\\img512enhanced_norm.npy", enhanced_ext)
# Creation of the enhanced maps
ext_nfo["coarse_map"] = extension_t.CoarseMap(enhanced_ext, ext_low_c, ext_high_c, ext_selem_pixel_c) # seuillage
......@@ -223,6 +231,8 @@ ext_nfo["lmp"], n_extensions = ms_.label(ext_nfo["map"], return_num=True)
# ext_nfo["lmp"] = relabel_sequential(ext_lmp)[0]
# n_extensions = ext_nfo["lmp"].max()
# np_.save("D:\\MorganeNadal\\img512enhanced_norm_hyst_morpho_2.npy", ext_nfo["lmp"])
extensions = tuple(
extension_t().FromMap(ext_nfo["lmp"], ext_scales, uid)
for uid in range(1, n_extensions + 1))
......@@ -362,14 +372,16 @@ print(f"\nElapsed Time={tm_.strftime('%Hh %Mm %Ss', elapsed_time)}")
if with_plot:
pl_.show()
# np_.save("D:\\MorganeNadal\\img512final_2.npy", som_nfo['soma_w_ext_lmp'])
po_.MaximumIntensityProjectionZ(som_nfo['soma_w_ext_lmp'])
# po_.MaximumIntensityProjectionZ(ext_nfo['lmp_soma'])
# --- Extract all the extensions of all somas as a graph
print('\n--- Graph extraction')
# Create the graphs
for soma in somas:
print(f" Soma {soma.uid}", end="")
ext_map = skl_map_t.FromShapeMap(ext_nfo['lmp_soma'] == soma.uid, store_widths=True, skeletonize=False) # do_post_thinning=True
# to remove pixel that are not breaking connectivity - FineMap in FromShapeMap
soma.skl_graph = skl_graph_t.FromSkeleton(ext_map, size_voxel=size_voxel_in_micron)
......@@ -381,8 +393,6 @@ for soma in somas:
# --- Find the root of the {ext+conn} graphs.
# Roots are the nodes of degree 1 that are to be linked to the soma
print(f" Soma {soma.uid}", end="")
soma.graph_roots = ge_.FindGraphsRootWithNodes(soma)
# soma.graph_roots = ge_.FindGraphsRootWithEdges(soma, ext_nfo)
......@@ -404,11 +414,16 @@ elapsed_time = tm_.gmtime(tm_.time() - start_time)
# Extract features
print('\n--- Features Extraction\n')
# Prms
number_of_bins = int(number_of_bins)
max_range = hist_step * number_of_bins - hist_min_length
number_of_bins_length = int(number_of_bins_length)
bins_length = np_.linspace(hist_min_length, hist_min_length + hist_step_length * number_of_bins_length, num=number_of_bins_length)
bins_length[-1] = np_.inf
number_of_bins_curvature = int(number_of_bins_curvature)
bins_curvature = np_.linspace(hist_min_curvature, hist_min_curvature + hist_step_curvature * number_of_bins_curvature, num=number_of_bins_curvature)
bins_curvature[-1] = np_.inf
# DF creation
features_df = ge_.ExtractFeaturesInDF(somas, size_voxel_in_micron, number_of_bins, max_range, hist_min_length, ext_scales)
# features_df.to_csv("...\features.csv")
features_df = ge_.ExtractFeaturesInDF(somas, size_voxel_in_micron, bins_length, bins_curvature, ext_scales)
features_df.to_csv("D:\\MorganeNadal\\M2 report\\features_512_.csv")
#
elapsed_time = tm_.gmtime(tm_.time() - start_time)
......
......@@ -54,7 +54,7 @@ channel : G
; Can take the values R, G or B.
; Can also be set to None (cf. README above).
size_voxel_in_micron
; size_voxel_in_micron -> X,Y,Z
; size_voxel_in_micron -> [X,Y,Z]
; Can also be set to None (cf. README above).
save_images
; if None, no saving. Otherwise, path where to save images # TODO add in search_parameters.py
......@@ -80,7 +80,7 @@ max_straight_sq_dist_c : 0.24050024 * (30 ** 2)
max_weighted_length_c : 0.24050024 * 20.0
[Frangi]
scale_range : 0.024,0.745
scale_range : (0.024,0.745)
; Stop at max 3.1 (<=> 0.745) for number of Z stacks < 18
; write min,max scale range
scale_step : 0.24
......@@ -99,12 +99,18 @@ method : c
hist_min_length : 0
; in micron
; by default, 0
hist_step : 6
hist_step_length : 6
; in micron
number_of_bins : 5
number_of_bins_length : 5
; by default, 5
; extensions generally do not exceed 30 microns
; histograms of extensions curvatures
hist_min_curvature : 0
hist_step_curvature : 6
number_of_bins_curvature : 5
[Program Running]
with_plot : False
in_parallel : False
......@@ -38,25 +38,20 @@ parameters.read('parameters.ini')
def IfNotFloat(section: str, key: str) -> float:
try:
value = parameters.getfloat(section, key)
return value
except:
return eval(parameters.get(section, key))
if parameters.get(section, key) is not None:
try:
value = parameters.getfloat(section, key)
return value
except:
return eval(parameters.get(section, key))
else:
return parameters.get(section, key)
# [Input]
data_path = parameters['Input']['data_path']
channel = parameters['Input']['channel']
try:
size_voxel_in_micron = parameters['Input']['size_voxel_in_micron']
if size_voxel_in_micron is not None:
size_voxel_in_micron = size_voxel_in_micron.split(',')
size_voxel_in_micron = list(float(size_voxel_in_micron[i]) for i in range(len(size_voxel_in_micron)))
except:
raise ValueError('The voxel size parameter is not given correctly. Write X,Y,Z without () or [] or spaces. Do not '
'forget ":" between size_voxel_in_micron and its value')
size_voxel_in_micron = IfNotFloat('Input', 'size_voxel_in_micron')
save_images = IfNotFloat('Input', 'save_images')
# [Somas]
soma_low_c = IfNotFloat('Somas', 'soma_low_c')
......@@ -76,14 +71,7 @@ max_weighted_length_c = IfNotFloat('Connexions', 'max_weighted_length_c')
# [Frangi]
try:
scale_range = parameters['Frangi']['scale_range']
scale_range = scale_range.split(',')
scale_range = tuple(float(scale_range[i]) for i in range(len(scale_range)))
except:
raise ValueError('The scale range parameter is not given correctly. Write min,max without () or [] or spaces. '
'Do not forget ":" between scale_range and its value')
scale_range = IfNotFloat('Frangi', 'scale_range')
scale_step = IfNotFloat('Frangi', 'scale_step')
alpha = IfNotFloat('Frangi', 'alpha')
beta = IfNotFloat('Frangi', 'beta')
......@@ -93,8 +81,11 @@ method = parameters['Frangi']['method']
# [Features Extraction]
hist_min_length = IfNotFloat('Features Extraction', 'hist_min_length')
hist_step = IfNotFloat('Features Extraction', 'hist_step')
number_of_bins = IfNotFloat('Features Extraction', 'number_of_bins')
hist_step_length = IfNotFloat('Features Extraction', 'hist_step_length')
number_of_bins_length = IfNotFloat('Features Extraction', 'number_of_bins_length')
hist_min_curvature = IfNotFloat('Features Extraction', 'hist_min_curvature')
hist_step_curvature = IfNotFloat('Features Extraction', 'hist_step_curvature')
number_of_bins_curvature = IfNotFloat('Features Extraction', 'number_of_bins_curvature')
# [Program running]
with_plot = parameters.getboolean('Program Running', 'with_plot')
......
......@@ -127,7 +127,6 @@ class edge_t:
if check_validity:
# A global condition: self.sites[0].size - 1 <= length
if cast(array_t, sq_lengths == 0).any():
np_.save("D:\\MorganeNadal\\site_as_array_in_SetLength.npy", sites_as_array)
raise ValueError("Edge: Repeated sites")
if cast(array_t, sq_lengths > self.sites.__len__()).any():
raise ValueError("Edge: Site gaps")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment