Mentions légales du service

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

usable version with choice btw w or wo dilatation/erosion.

For the moment, more relevant results (biologically speaking) without dilatation/erosion.
parent c5b6acb2
No related branches found
No related tags found
No related merge requests found
......@@ -84,11 +84,10 @@ def ShortestPathFromToN(
extension: extension_t,
costs: array_t,
candidate_points_fct: Callable,
all_end_points : tuple = None,
all_end_points: tuple = None,
extensions: tuple = None,
max_straight_sq_dist: float = np_.inf,
erode_path: bool = True,
strict_erosion: bool = True,
erode_path: bool = False,
) -> Tuple[site_path_h, float]:
'''
Find the shortest weighted path between endpoints and soma closest contour points.
......@@ -103,48 +102,43 @@ def ShortestPathFromToN(
# Erode the candidate points of the extensions for Ext <-> Ext connexion
if erode_path:
if candidate_indexing is not None:
if strict_erosion:
# reformat to modify them
candidate_points = list(candidate_points)
candidate_indexing_var = list(candidate_indexing)
candidate_indexing = []
for idx in candidate_indexing_var:
idx = list(idx)
candidate_indexing.append(idx)
# Delete the points that are not endpoints and that are less than 2 pixels away from the closest endpoint
# -- important for dilatation/erosion process
for candidate, indx in enumerate(candidate_points):
# Verify if end point
if candidate not in zip(*all_end_points):
# Here necessary to delete the 2 closest points next to the end points
# because if the all extension is candidate there might be a endpoint
# that will be polluted by the connection
not_allowed = set()
for e_p in zip(*all_end_points):
not_allowed_ = set(
(e_p[0] + i, e_p[1] + j, e_p[2] + k)
for i in (-2, -1, 0, 1, 2)
for j in (-2, -1, 0, 1, 2)
for k in (-2, -1, 0, 1, 2)
if i != 0 or j != 0 or k != 0)
not_allowed |= not_allowed_
if candidate in not_allowed:
for i in range(3):
candidate_indexing[i].pop(indx)
candidate_points.remove(candidate)
# ext_sites = set()
# for extension in extensions: ext_sites.add(set(zip(*extension.sites[2:-2])))
# Verify if more than 2 pixels away from the closest endpoint
# if candidate not in ext_sites:
# reformatting
candidate_points = tuple(candidate_points)
candidate_indexing = tuple(candidate_indexing)
# reformat to modify them
candidate_points = list(candidate_points)
candidate_indexing_var = list(candidate_indexing)
candidate_indexing = []
for idx in candidate_indexing_var:
idx = list(idx)
candidate_indexing.append(idx)
# Delete the points that are not endpoints and that are less than 2 pixels away from the closest endpoint
# -- important for dilatation/erosion process
for candidate, indx in enumerate(candidate_points):
# Verify if end point
if candidate not in zip(*all_end_points):
# Here necessary to delete the 2 closest points next to the end points
# because if the all extension is candidate there might be a endpoint
# that will be polluted by the connection
not_allowed = set()
for e_p in zip(*all_end_points):
not_allowed_ = set(
(e_p[0] + i, e_p[1] + j, e_p[2] + k)
for i in (-2, -1, 0, 1, 2)
for j in (-2, -1, 0, 1, 2)
for k in (-2, -1, 0, 1, 2)
if i != 0 or j != 0 or k != 0)
not_allowed |= not_allowed_
if candidate in not_allowed:
for i in range(3):
candidate_indexing[i].pop(indx)
candidate_points.remove(candidate)
# reformatting
candidate_points = tuple(candidate_points)
candidate_indexing = tuple(candidate_indexing)
# Erode the end_point of the extension AND the extension candidate points in the costs map
costs = Erode(candidate_points, costs, extension, extensions, image, all_end_points=all_end_points, strict_erosion=strict_erosion)
Erode(candidate_points, costs, extension, extensions, image, all_end_points=all_end_points)
# If no path, return empty tuple for path and infinite path length.
if candidate_points is None:
......@@ -183,8 +177,8 @@ def ShortestPathFromToN(
def ValidateConnection(
glial_cmp: glial_cmp_t, extension: glial_cmp_t, end_point: tuple, dijkstra_path: site_path_h, costs: array_t
) -> array_t:
glial_cmp: glial_cmp_t, extension: glial_cmp_t, end_point: tuple, dijkstra_path: site_path_h, costs: array_t,
) -> None:
'''
Keep the connection path in the glial_cmp.
Add the extension to the extensions list of the glial_cmp.
......@@ -195,8 +189,6 @@ def ValidateConnection(
if connection_path.__len__() == 0:
connection_path = None
costs[connection_path] = np_.inf
# Store the connexion path in the glial_cmp
glial_cmp.connection_path[extension.uid] = connection_path
# Add the connected extension to the list of the extensions of the glial_cmp
......@@ -204,16 +196,16 @@ def ValidateConnection(
# TODO BackReferenceSoma
extension.BackReferenceSoma(glial_cmp)
# Add the site of the connexion between the extension and the soma, for each soma and for ech extension
# Add the site of the connexion between the extension and the soma, for each soma and for each extension
# restrain the verification to the soma <-> ext step
# Store the new endpoints of the extended extension - TODO update the end point vector
if type(glial_cmp) is soma_t:
# Store the new endpoints of the extended extension
# print(end_point)
end_point = UpdateEndPointsWithConnexionPath(glial_cmp, connection_path, end_point)
# print(end_point)
end_point = UpdateEndPointsWithConnexionPath(connection_path, end_point)
glial_cmp.ext_roots.append((extension.uid, end_point))
if connection_path is not None:
costs[connection_path] = np_.inf
# add the connexion sites to the extension sites
ext_sites = np_.asarray(extension.sites)
......@@ -222,25 +214,35 @@ def ValidateConnection(
sites = ext_sites[i].tolist()
sites += list(connection_path[i])
extension.sites[i] = np_.asarray(sites, dtype=np_.int64)
# # reorder the new extension sites
# extension.sites = _ReOrderedSites(extension.sites)
# reformat
extension.sites = tuple(extension.sites)
# Dilate extensions
costs = Dilate(extension.sites, costs)
return costs
def UpdateEndPointsWithConnexionPath(soma: soma_t, connexion_path: tuple, end_point: tuple) -> tuple:
def UpdateEndPointsWithConnexionPath(connexion_path: tuple, end_point: tuple) -> tuple:
#
if connexion_path is None:
return end_point
else:
# print(end_point)
# /!\ may yield a bug
# Update the end point vector - delete the old endpoint
# # reformat to modify them
# all_end_points_var = list(all_end_points)
# all_end_points = []
# for i in all_end_points_var:
# indx = list(i)
# all_end_points.append(indx)
# # delete the connected end point
# if end_point in zip(*all_end_points):
# idx = list(zip(*all_end_points)).index(end_point)
# for i in range(3):
# all_end_points[i].pop(idx)
# else:
# print("WARNING: End point not in the all end points vectors !")
# Search the connection point link to the extension
connexion_path = tuple(zip(*connexion_path))
# print(connexion_path[0], connexion_path[-1])
close_end_pt = tuple(
(end_point[0] + i, end_point[1] + j, end_point[2] + k)
for i in (-1, 0, 1)
......@@ -249,13 +251,19 @@ def UpdateEndPointsWithConnexionPath(soma: soma_t, connexion_path: tuple, end_po
if i != 0 or j != 0 or k != 0)
if connexion_path[0] in close_end_pt:
# for i in range(3):
# all_end_points.append(connexion_path[-1][i])
# all_end_points = tuple(all_end_points)
return connexion_path[-1]
elif connexion_path[-1] in close_end_pt:
# for i in range(3):
# all_end_points.append(connexion_path[0][i])
# all_end_points = tuple(all_end_points)
return connexion_path[0]
def Dilate(path: tuple, costs_map: array_t, cost: float = np_.inf) -> array_t:
def Dilate(path: tuple, costs_map: array_t, cost: float = np_.inf) -> None:
'''
Put to the value cost in the cost map the neighbors voxels of a given path.
The path must be in the format: array([[x1,x2,...],[y1,y2,...],[z1,z2,...]])
......@@ -273,17 +281,14 @@ def Dilate(path: tuple, costs_map: array_t, cost: float = np_.inf) -> array_t:
if (ext > (0, 0, 0)) and (ext[0] < shape[0]) and (ext[1] < shape[1]) and (ext[2] < shape[2]):
costs_map[int(ext[0]), int(ext[1]), int(ext[2])] = cost
return costs_map
def Erode(path: Tuple[tuple],
costs_map: array_t,
extension: extension_t,
extensions: tuple,
image: array_t,
endpt=None,
all_end_points=None,
strict_erosion: bool = False) -> array_t:
) -> None:
'''
Erode the voxels of a given path or point, without eroding the neighboring extension pixels and their neighbors.
The path must be in the format: Tuple(tuple(x1, y1, z1), ...)
......@@ -292,30 +297,18 @@ def Erode(path: Tuple[tuple],
new_path = []
for point in path:
if endpt is None:
# find out whether this is a end point or not
if point in zip(*all_end_points):
endpt = True
else:
endpt = False
elif endpt is True:
costs_map = ErodeEndPoint(point, costs_map, extension, image)
elif endpt is False:
# find out whether this is a end point or not
if point in zip(*all_end_points):
ErodeEndPoint(point, costs_map, extension, image)
else:
# build a new path with no endpoints inside
new_path.append(point)
else:
raise ValueError("Value of endpt in Erode() not allowed. Allowed values: (None, True, False).")
costs_map = ErodePath(tuple(new_path), costs_map, extensions, image, strict_erosion=strict_erosion)
return costs_map
if new_path.__len__() > 0:
ErodePath(tuple(new_path), costs_map, extensions, image)
def ErodeEndPoint(end_point: tuple, costs_map: array_t, extension: extension_t, image: array_t) -> array_t:
def ErodeEndPoint(end_point: tuple, costs_map: array_t, extension: extension_t, image: array_t) -> None:
'''
Erode the endpoint of the extension to be connected and its neighbors.
'''
......@@ -348,10 +341,8 @@ def ErodeEndPoint(end_point: tuple, costs_map: array_t, extension: extension_t,
if (tuple(ext) > (0, 0, 0)) and (tuple(ext)[0] < shape[0]) and (tuple(ext)[1] < shape[1]) and (tuple(ext)[2] < shape[2]):
costs_map[ext[0], ext[1], ext[2]] = 1.0 / (image[ext[0], ext[1], ext[2]] + 1.0)
return costs_map
def ErodePath(path: tuple, costs_map: array_t, extensions: tuple, image: array_t, strict_erosion:bool = False) -> array_t:
def ErodePath(path: tuple, costs_map: array_t, extensions: tuple, image: array_t) -> None:
'''
Erode the voxels of a given path, without eroding the neighboring extension pixels and their neighbors.
'''
......@@ -373,18 +364,16 @@ def ErodePath(path: tuple, costs_map: array_t, extensions: tuple, image: array_t
for extension in extensions:
for site in zip(*extension.sites):
if (site in dilated) and (site not in path):
dilated_site = set(
(site[0] + i, site[1] + j, site[2] + k)
for i in (-1, 0, 1)
for j in (-1, 0, 1)
for k in (-1, 0, 1)
if i != 0 or j != 0 or k != 0)
dilated.remove(site)
if not strict_erosion:
# Here the work of the strict erosion is already done in ShortestPathFromToN.
# So we allow more voxels to be erode in this condition in ErodePath.
dilated = dilated.difference(dilated_site)
# # Here the work of the strict erosion is already done in ShortestPathFromToN.
# # So we allow more voxels to be erode in this condition in ErodePath.
# dilated_site = set(
# (site[0] + i, site[1] + j, site[2] + k)
# for i in (-1, 0, 1)
# for j in (-1, 0, 1)
# for k in (-1, 0, 1)
# if i != 0 or j != 0 or k != 0)
# dilated = dilated.difference(dilated_site)
dilated = list(dilated)
......@@ -392,6 +381,4 @@ def ErodePath(path: tuple, costs_map: array_t, extensions: tuple, image: array_t
for ext in dilated:
if (tuple(ext) > (0, 0, 0)) and (tuple(ext)[0] < shape[0]) and (tuple(ext)[1] < shape[1]) and (
tuple(ext)[2] < shape[2]):
costs_map[ext[0], ext[1], ext[2]] = 1.0 / (image[ext[0], ext[1], ext[2]] + 1.0)
return costs_map
\ No newline at end of file
costs_map[ext[0], ext[1], ext[2]] = 1.0 / (image[ext[0], ext[1], ext[2]] + 1.0)
\ No newline at end of file
This diff is collapsed.
......@@ -49,38 +49,28 @@ parameter3 : None
; then your parameter has the value string: 'None', and not None
[Input]
data_path : D:\\MorganeNadal\\IBA1-Microglies
# D:\\MorganeNadal\\IBA1-Microglies\\DIO_1H_16_1.58_2.1\DIO_1H_16_1.58_2.1_3.tif
#D:\\MorganeNadal\\IBA1-Microglies\\CHO_1H_D_1.70_3.3\\CHO_1H_D_1.70_3.3_1.tif
#.\data\DIO_6H_6_1.70bis_2.2_3.tif
#D:\MorganeNadal\IBA1-Microglies\standard conditions\020620_ST8_20W_1_2.lif - Position 3.tif
#D:\\MorganeNadal\\IBA1-Microglies\\standard conditions\\ST8_crop2(1024x1024)_vert.tif
data_path : .\\data\\DIO_6H_6_1.70bis_2.2_3.tif
; direct data path to the image
channel
channel : G
; Can take the values R, G or B.
; Can also be set to None (cf. README above).
size_voxel_in_micron
#: [0.167,0.167,0.5]
#: [0.071, 0.071, 0.4997]
; size_voxel_in_micron -> [X,Y,Z]
; Can also be set to None (cf. README above).
crop_image
# TODO
save_images : D:\\MorganeNadal\\Results\\Images
save_images : \\path_where_to_save_MIP_and_graphs
; if None, no saving. Otherwise, path where to save images (MIP & graphs)
condition
; TODO CHO, DIO, ...
duration
; TODO 1H, 3H, 1W, 3W, ...
save_csv : \\path_where_to_save_features_csv
; where to save the csv. if None, by default it is in the .tif directory
dilatation_erosion : False
; Choose whether to perform erosion/dilation on the extensions during the connexion process.
; For the moment, better results are achieved without it, but doing dilatation_erosion is theoretically more rigorous
statistical_analysis : True
[Somas]
soma_low_c : 0.15
# low = 10 #0.15
; this is a coefficient => not in micron
soma_high_c : 0.7126
; this is a coefficient => not in micron
# high = 67.4 # 0.7126
soma_selem_micron_c : 0.481
soma_min_area_c : 58
soma_max_area_c : 580
......@@ -89,23 +79,17 @@ soma_max_area_c : 580
adapt_hist_equalization : False
; for hysteresis
ext_low_c : 10
#7.5e-8
#1e-20
# low = 0.02
ext_high_c : 0.6
#1e-5
# 0.5e-5
# high = 0.04
; for morphological cleaning
ext_selem_micron_c : 0.2405
ext_min_area_c : 5.7840
ext_max_length_c : 60
[Connexions]
max_straight_sq_dist_c : 216.45
max_weighted_length_c : 4.81
max_straight_sq_dist_c : 217
max_weighted_length_c : 5
[Frangi]
; Values can be adapted to the image with the interface of frangi3gui.py
scale_range : (0.1,3.1)
; Stop at max x.1 with x <= sqrt(Z/2)
; ex: 3.1 for Z stacks < 18 and 5.1 for Z stacks < 50
......@@ -113,8 +97,6 @@ scale_step : 1.0
alpha : 0.8
beta : 0.5
frangi_c : 30
## 12.5 if normalized btw 0 and 1
# 60.12506 # 500.0
diff_mode : indirect
bright_on_dark : True
method : c
......@@ -130,7 +112,6 @@ hist_step_length
; in micron
number_of_bins_length
#: 5
; by default, 5
; extensions generally do not exceed 30 microns
; if the above parameters are set to None, you can directly use the boundaries of your choice for the histogram:
......
......@@ -52,8 +52,9 @@ def IfNotFloat(section: str, key: str) -> Union[Union[float, str], Any]:
data_path = parameters['Input']['data_path']
channel = parameters['Input']['channel']
size_voxel_in_micron = IfNotFloat('Input', 'size_voxel_in_micron')
crop_image = IfNotFloat('Input', 'crop_image')
dilatation_erosion = parameters.getboolean('Input', 'dilatation_erosion')
save_images = parameters['Input']['save_images']
save_csv = parameters['Input']['save_csv']
statistical_analysis = parameters.getboolean('Input', 'statistical_analysis')
# [Somas]
......@@ -69,7 +70,6 @@ ext_low_c = IfNotFloat('Extensions', 'ext_low_c')
ext_high_c = IfNotFloat('Extensions', 'ext_high_c')
ext_selem_micron_c = IfNotFloat('Extensions', 'ext_selem_micron_c')
ext_min_area_c = IfNotFloat('Extensions', 'ext_min_area_c')
ext_max_length_c = IfNotFloat('Extensions', 'ext_max_length_c')
# [Connexions]
max_straight_sq_dist_c = IfNotFloat('Connexions', 'max_straight_sq_dist_c')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment