Mentions légales du service

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

EROSION/DILATATION during connexion: added possibility to choose between 2...

EROSION/DILATATION during connexion: added possibility to choose between 2 erosion conditions. The strict one seems to be best (strict_erosion=True)
parent 6f64d820
No related branches found
No related tags found
No related merge requests found
......@@ -88,6 +88,7 @@ def ShortestPathFromToN(
extensions: tuple = None,
max_straight_sq_dist: float = np_.inf,
erode_path: bool = True,
strict_erosion: bool = True,
) -> Tuple[site_path_h, float]:
'''
Find the shortest weighted path between endpoints and soma closest contour points.
......@@ -102,47 +103,48 @@ def ShortestPathFromToN(
# Erode the candidate points of the extensions for Ext <-> Ext connexion
if erode_path:
if candidate_indexing is not None:
# 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 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 (-1, 0, 1)
for j in (-1, 0, 1)
for k in (-1, 0, 1)
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)
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)
# 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)
costs = Erode(candidate_points, costs, extension, extensions, image, all_end_points=all_end_points, strict_erosion=strict_erosion)
# If no path, return empty tuple for path and infinite path length.
if candidate_points is None:
......@@ -274,7 +276,14 @@ def Dilate(path: tuple, costs_map: array_t, cost: float = np_.inf) -> array_t:
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) -> array_t:
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:
'''
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), ...)
......@@ -301,7 +310,7 @@ def Erode(path: Tuple[tuple], costs_map: array_t, extension: extension_t, extens
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)
costs_map = ErodePath(tuple(new_path), costs_map, extensions, image, strict_erosion=strict_erosion)
return costs_map
......@@ -342,7 +351,7 @@ def ErodeEndPoint(end_point: tuple, costs_map: array_t, extension: extension_t,
return costs_map
def ErodePath(path: tuple, costs_map: array_t, extensions: tuple, image: array_t) -> array_t:
def ErodePath(path: tuple, costs_map: array_t, extensions: tuple, image: array_t, strict_erosion:bool = False) -> array_t:
'''
Erode the voxels of a given path, without eroding the neighboring extension pixels and their neighbors.
'''
......@@ -372,7 +381,10 @@ def ErodePath(path: tuple, costs_map: array_t, extensions: tuple, image: array_t
if i != 0 or j != 0 or k != 0)
dilated.remove(site)
dilated = dilated.difference(dilated_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)
dilated = list(dilated)
......
......@@ -943,6 +943,7 @@ def NutriMorph(data_path: str,
all_end_points=all_end_points,
max_straight_sq_dist=max_straight_sq_dist_c,
erode_path=True,
strict_erosion=True,
)
# Keep the connexion only if inferior to the allowed max weighted distance
......@@ -1102,7 +1103,11 @@ if __name__ == '__main__':
## TODO /!\ Still errors in the graph = some extensions are tangent to each other.
# Verify Dilatation and Erosion!
# Save to .csv in the parent repository
concatenated_features_df.to_csv(f"{data_path}\\features.csv")
# concatenated_features_df.to_csv(f"{data_path}\\features.csv")
concatenated_features_df.to_csv(f"{save_images}\\features.csv")
else:
raise ImportError("Not a valid data path!")
# --- TODO Clustering with this df and module features_analysis.py
# if statistical_analysis:
......
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