Mentions légales du service

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

solved soma_volume/convex_hull_volume issue

parent 62d76ae3
No related branches found
No related tags found
No related merge requests found
......@@ -142,19 +142,19 @@ def polyToParams3D(ellipsoid_coef: array_t, printMe: bool = False) -> tuple:
def GetConvexHull3D(soma_sites: site_h) -> tuple:
#
three_D = np_.stack((soma_sites[0], soma_sites[1], soma_sites[2]), axis=-1)
hull_three_D = ConvexHull(three_D)
volume_of_CH = hull_three_D.volume
soma_3D = np_.stack((soma_sites[0], soma_sites[1], soma_sites[2]), axis=-1)
hull_3D = ConvexHull(soma_3D)
volume_hull = hull_3D.volume
len_hull = len(hull_three_D.vertices)
len_hull = len(hull_3D.vertices)
hull = np_.zeros((len_hull, 3))
for i in range(len(hull_three_D.vertices)):
hull[i] = three_D[hull_three_D.vertices[i]]
for i in range(len(hull_3D.vertices)):
hull[i] = soma_3D[hull_3D.vertices[i]]
convex_hull = np_.transpose(hull)
return convex_hull, volume_of_CH
return convex_hull, volume_hull
def FindBestFittingEllipsoid3D(soma: soma_t) -> tuple:
......@@ -164,7 +164,7 @@ def FindBestFittingEllipsoid3D(soma: soma_t) -> tuple:
"""
# get convex hull
convex_hull = GetConvexHull3D(soma.sites)[0]
convex_hull, volume_hull = GetConvexHull3D(soma.sites)
# fit ellipsoid on the convex hull
# # get ellipsoid polynomial coefficients
......@@ -172,4 +172,4 @@ def FindBestFittingEllipsoid3D(soma: soma_t) -> tuple:
# # get ellipsoid 3D parameters
center, axes, orientation, spherical_coor = polyToParams3D(ellipsoid_coef, False)
return ellipsoid_coef, center, axes, orientation, spherical_coor
return ellipsoid_coef, center, axes, orientation, spherical_coor, convex_hull, volume_hull
......@@ -280,19 +280,9 @@ def ExtractFeaturesInDF(name_file, somas, size_voxel_in_micron: list, bins_lengt
for soma in somas:
# -- Soma features
# Volume of the soma
volume_pixel_micron = round(np_.prod(size_voxel_in_micron), 4)
soma.volume_soma_micron = volume_pixel_micron * len(soma.sites[0])
# Calculates volume of soma's convex hull
volume_convex_hull = volume_pixel_micron * bf_.GetConvexHull3D(soma.sites)[1]
# Volume of the soma / Volume of its convex hull gives the info about the convexity of the soma
# If close to 0, the soma has a lot of invaginations, if close to 1, it is smooth and convex
Coef_V_soma__V_convex_hull = soma.volume_soma_micron / volume_convex_hull
# Axes of the best fitting ellipsoid
# a > b > c
_, _, soma.axes_ellipsoid, _, spherical_coor = bf_.FindBestFittingEllipsoid3D(soma)
_, _, soma.axes_ellipsoid, _, spherical_coor, _, volume_convex_hull = bf_.FindBestFittingEllipsoid3D(soma)
# This ratios give info about the shape of the soma. ex: rather flat, rather patatoide, rather spherical...
Coef_axes_ellips_b__a = soma.axes_ellipsoid[0] / soma.axes_ellipsoid[2]
......@@ -302,6 +292,16 @@ def ExtractFeaturesInDF(name_file, somas, size_voxel_in_micron: list, bins_lengt
spherical_angles_eva = (spherical_coor[0][1], spherical_coor[0][2])
spherical_angles_evb = (spherical_coor[1][1], spherical_coor[1][2])
# Volume of the soma
soma.volume_soma_micron = in_.ToMicron(len(soma.sites[0]), size_voxel_in_micron, dimension=(0, 1, 2), decimals=3)
# Calculates volume of soma's convex hull
volume_convex_hull = in_.ToMicron(volume_convex_hull, size_voxel_in_micron, dimension=(0, 1, 2))
# Volume of the soma / Volume of its convex hull gives the info about the convexity of the soma
# If close to 0, the soma has a lot of invaginations, if close to 1, it is smooth and convex
Coef_V_soma__V_convex_hull = soma.volume_soma_micron / volume_convex_hull
# TODO Solve issue V_soma > V_convexHull
# -- Extension features
# Graph features
......
......@@ -147,7 +147,7 @@ def FindVoxelDimensionInMicron(data_path: str, size_voxel_in_micron: list = None
raise ValueError('/!\ Unable to find the voxel dimensions in micron. Specify it in the parameters.')
def ToPixel(micron: float, voxel_size_micron: array_t, dimension: tuple = (0,), decimals: int = None) -> int:
def ToPixel(micron: float, voxel_size_micron: list, dimension: tuple = (0,), decimals: int = None) -> int:
'''
Dimension correspond to the axis (X,Y,Z) = (0,1,2). Can be used for distance, area and volumes.
'''
......@@ -155,7 +155,7 @@ def ToPixel(micron: float, voxel_size_micron: array_t, dimension: tuple = (0,),
return round(micron/(mt_.prod(voxel_size_micron[axis] for axis in dimension)), decimals)
def ToMicron(pixel: float, voxel_size_micron: array_t, dimension: tuple = (0,), decimals: int = None) -> float:
def ToMicron(pixel: float, voxel_size_micron: list, dimension: tuple = (0,), decimals: int = None) -> float:
'''
Dimension correspond to the axis (X,Y,Z) = (0,1,2). Can be used for distance, area and volumes.
'''
......
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