OSCR

Curvature-based machine-learning method for automated segmentation of dendritic spines.

Code ↔ Paper

7 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 7 matches
  1. [1] § Results › Dendritic spine morphologic parameters ↔ dend_analysis/dend_fun_0/get_path.py, lines 1977–2061 · score 0.70 · head diameter, neck diameter, spine volume, spine area, spine length, histograms
  2. [2] § Materials and methods › DNN approach for spine and shaft analysis › Skeletonization ↔ dend_analysis/dend_fun_0/get_wrap.py, lines 92–128 · score 0.68 · sampled point cloud, orients normals, Poisson, wrap, reconstruction, geometric
  3. [3] § Materials and methods › DNN approach for spine and shaft analysis ↔ dend_analysis/dend_fun_0/side_bar.py, lines 493–574 · score 0.67 · informed neural network, Machine learning, architectures, CNNs, DNN, geometrical
  4. [4] § Materials and methods › DNN approach for spine and shaft analysis › Skeletonization ↔ dend_analysis/dend_fun_2/help_pinn_data_222.py, lines 46–67 · score 0.65 · sampled point cloud, orients normals, Poisson, wrap, geometric, mesh
  5. [5] § Materials and methods › DNN approach for spine and shaft analysis › Dendrite spine-shaft segmentation using dendritic-branch regions (DNN3) ↔ dend_analysis/main.ipynb, lines 330–435 · score 0.55 · gauss sq, length sh, kmean, vert, skl, distance
  6. [6] § Materials and methods › Dataset description › Training dataset ↔ dend_analysis/dend_fun_0/help_pinn_data_fun.py, lines 494–589 · score 0.52 · KD tree, radius threshold, map, neighbor, branch, vertices
  7. [7] § Materials and methods › Dataset description › Training dataset ↔ dend_analysis/dend_fun_2/help_pinn_data_222.py, lines 391–520 · score 0.52 · KD tree, radius threshold, map, neighbor, branch, vertices

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Python · 1,253 lines · 66 KB · no license · 2 matches

  1. import sys
  2. import os
  3. import numpy as np
  4. os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
  5. import numpy as np
  6. import tensorflow as tf
  7. tf.config.run_functions_eagerly(True)
  8. DTYPE='float32'
  9. import pickle
  10. from dend_fun_0.curvature import curv_mesh as curv_mesh
  11. import dend_fun_0.help_funn as hff
  12. from dend_fun_0.help_funn import dendrite, cluster_class,label_cluster,Branch_division,get_intensity,Threshold_curv,Impute_intensity, order_points_along_pca
  13. from dend_fun_0.help_funn import mappings_vertices,clust_pca,dendrite_io,volume,closest_distances_group,find_min_max_no_cross,Curve_length
  14. DTYPE = tf.float32
  15. from sklearn.neighbors import KDTree
  16. from dend_fun_0.obj_get import Obj_to_vertices,get_obj_filenames_with_indices_2
  17. from dend_fun_2.metric import center_curvature, get_kmean,get_kmean_mean ,get_center_lines
  18. from dend_fun_0.help_pinn_data_fun import get_model,model_shaft,pinn_data_init
  19. device = "/GPU:0" if tf.config.list_physical_devices('GPU') else "/CPU:0"
  20. from dend_fun_0.help_spine_division import region_branch
  21. import random
  22. np.random.seed(42)
  23. tf.random.set_seed(42)
  24. random.seed(42)
  25. from collections import defaultdict
  26. import trimesh
  27. from scipy.spatial import KDTree
  28. import open3d as o3d
  29. from skimage.measure import label
  30. from skimage.morphology import skeletonize
  31. from scipy.ndimage import label
  32. def get_wrap(vertices,faces,number_of_points=8000,radius=0.9, max_nn=30):
  33. mesh = trimesh.Trimesh(vertices=vertices , faces=faces)
  34. o3d_mesh = o3d.geometry.TriangleMesh()
  35. o3d_mesh.vertices = o3d.utility.Vector3dVector(mesh.vertices)
  36. o3d_mesh.triangles = o3d.utility.Vector3iVector(mesh.faces)
  37. pcd = o3d_mesh.sample_points_poisson_disk(number_of_points=number_of_points)
  38. # Estimate and orient normals
  39. pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=radius, max_nn=max_nn))
  40. pcd.orient_normals_consistent_tangent_plane(k=10)
  41. mesh_poisson, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson( pcd,
  42. depth=12, # adjust octree depth as needed
  43. width=0, # default
  44. scale=1.1, # default scaling
  45. linear_fit=False,
  46. n_threads=1 ,
  47. )
  48. return np.asarray(mesh_poisson.vertices), np.asarray(mesh_poisson.triangles)
  49. def get_contraction(vertices, skeleton_points, alpha=0.5):
  50. tree = KDTree(skeleton_points)
  51. idx = tree.query(vertices )[1]
  52. nearest_skel = skeleton_points[idx ]
  53. return (1 - alpha) * vertices + alpha * nearest_skel
  54. class mesh_resize():
  55. def __init__(self,vertices,faces,target_number_of_triangles=6000, ):
  56. self.vertices=vertices
  57. mesh = trimesh.Trimesh(vertices=vertices, faces=faces)
  58. o3d_mesh = o3d.geometry.TriangleMesh()
  59. o3d_mesh.vertices = o3d.utility.Vector3dVector(mesh.vertices)
  60. o3d_mesh.triangles = o3d.utility.Vector3iVector(mesh.faces)
  61. o3d_mesh = o3d_mesh.simplify_quadric_decimation(target_number_of_triangles=target_number_of_triangles)
  62. self.mesh = trimesh.Trimesh(
  63. vertices=np.asarray(o3d_mesh.vertices),
  64. faces=np.asarray(o3d_mesh.triangles)
  65. )
  66. def reduce_rhs(self, labels): return labels[KDTree(self.vertices).query(self.mesh.vertices)[1]]
  67. def reduce_to_full_rhs(self, labels): return labels[KDTree(self.mesh.vertices).query(self.vertices)[0]]
  68. class mesh_to_skeleton():
  69. def __init__(self,vertices,faces,target_number_of_triangles=6000,voxel_resolution = 128,tf_largest=False,disp_infos=True,tf_resize=True):
  70. self.vertices=vertices
  71. if tf_resize:
  72. mrs=mesh_resize(vertices,faces,target_number_of_triangles=target_number_of_triangles, )
  73. self.mesh=mrs.mesh
  74. else:
  75. self.mesh = trimesh.Trimesh(
  76. vertices=np.asarray(vertices),
  77. faces=np.asarray(faces)
  78. )
  79. edges = np.median(self.mesh.edges_unique_length) * 0.25
  80. print('mesh_to_skeleton-------edge----------',edges)
  81. voxelized = self.mesh.voxelized(pitch=(edges))
  82. filled = voxelized.fill()
  83. voxels = filled.matrix.astype(bool)
  84. if disp_infos:
  85. print("Voxel grid shape:", voxels.shape,)
  86. # skeleton_voxels = skeletonize_3d(voxels)
  87. skeleton_voxels = skeletonize(voxels)
  88. skeleton_coords = np.argwhere(skeleton_voxels)
  89. if tf_largest:
  90. labeled = label(skeleton_voxels)
  91. largest_label = np.argmax(np.bincount(labeled.flat)[1:]) + 1
  92. skeleton_voxels = labeled == largest_label
  93. if skeleton_coords.size == 0:
  94. print('--------------------',voxel_resolution,target_number_of_triangles)
  95. raise ValueError("No skeleton found — something went wrong in voxelization.")
  96. min_bound = self.mesh.bounds[0]
  97. pitch = filled.pitch
  98. self.skeleton_points = skeleton_coords * pitch + min_bound
  99. tree = KDTree(self.skeleton_points)
  100. distances, self.skl_index = tree.query(vertices)
  101. self.distances=distances
  102. self.dist_norm = (distances - distances.min()) / (distances.max() - distances.min())
  103. def mapping(self):
  104. self.skeleton_to_vertices = defaultdict(list)
  105. for vertex, skl_idx in zip(self.vertices, self.skl_index):
  106. if skl_idx not in self.skeleton_to_vertices:
  107. self.skeleton_to_vertices[skl_idx] = []
  108. self.skeleton_to_vertices[skl_idx].append(vertex)
  109. def mapping_inv(self, skeleton_vec):
  110. if not hasattr(self, 'skeleton_to_vertices'):
  111. self.mapping()
  112. vertices_mapped=[]
  113. for vec in skeleton_vec:
  114. vertices_mapped.extend(self.skeleton_to_vertices[vec])
  115. return vertices_mapped
  116. def reduce_rhs(self, labels): return labels[KDTree(self.vertices).query(self.mesh.vertices)[1]]
  117. def reduce_to_full_rhs(self, labels): return labels[KDTree(self.mesh.vertices).query(self.vertices)[0]]
  118. def def_mesh_to_skeleton_finder(vertices,faces,
  119. interval_voxel_resolution=None,
  120. interval_target_number_of_triangles=None,
  121. tf_largest=False,
  122. disp_infos=True,
  123. min_voxel_resolution=20,
  124. min_target_number_of_triangles=100,
  125. tf_division=False
  126. ):
  127. ktrr=KDTree(vertices)
  128. skss={}
  129. cv=1e100
  130. n_vert=len(vertices)
  131. nskl=None
  132. interval_target_number_of_triangles=interval_target_number_of_triangles if interval_target_number_of_triangles is not None else [1]
  133. if disp_infos:
  134. print('Start mesh_to_skeleton')
  135. print('------------------------------------')
  136. print('interval_target_number_of_triangles =',interval_target_number_of_triangles)
  137. print('interval_voxel_resolution =',interval_voxel_resolution)
  138. print('len(vertices) =',n_vert)
  139. for vv in interval_target_number_of_triangles:
  140. for uu in interval_voxel_resolution:
  141. n_voxel_resolution =uu if not tf_division else max(n_vert//uu,min_voxel_resolution)
  142. target_number_of_triangles =vv if not tf_division else max(n_vert//vv,min_target_number_of_triangles)
  143. print('n_voxel_resolution,target_number_of_triangles =',n_voxel_resolution,target_number_of_triangles)
  144. nskl=mesh_to_skeleton(vertices=vertices,
  145. faces=faces,
  146. voxel_resolution =n_voxel_resolution,
  147. target_number_of_triangles=target_number_of_triangles,
  148. tf_largest=tf_largest,
  149. disp_infos=disp_infos)
  150. distan = ktrr.query(nskl.skeleton_points)[0]
  151. cvtmp= np.std(distan) / np.mean(distan)
  152. if cvtmp<cv:
  153. cv=cvtmp
  154. uutmp=uu
  155. skl=nskl
  156. best_target_number_of_triangles=target_number_of_triangles,vv
  157. best_voxel_resolution=n_voxel_resolution,uu
  158. if disp_infos:
  159. print('The best target_number_of_triangles =',best_target_number_of_triangles)
  160. print('The best voxel_resolution =',best_voxel_resolution)
  161. return skl
  162. def get_model(base_features ,vcv_length, model_sufix, add_param=None ):
  163. vcv_length =np.asarray(vcv_length).reshape(-1, 1)
  164. if model_sufix.startswith("opt"):
  165. base_features.append(hff.normalize(vcv_length) )
  166. return base_features
  167. class mapping_skl():
  168. def __init__(self,vertices,skeleton_points, ):
  169. self.vertices=vertices
  170. tree = KDTree( skeleton_points)
  171. _, skl_index = tree.query(vertices)
  172. self.mappk={}
  173. for fb,vf in zip(skl_index,vertices):
  174. fbv=tuple(skeleton_points[fb])
  175. if fbv not in self.mappk:
  176. self.mappk[fbv]=[]
  177. self.mappk[fbv].append(vf)
  178. def mapping_inv(self, skeleton_points):
  179. vertices_mapped=[]
  180. for fb in skeleton_points:
  181. fbv=tuple(fb)
  182. vertices_mapped.extend(self.mappk[fbv])
  183. return np.array(vertices_mapped)
  184. def get_head_neck_mectric(self,metric_save,metrics,dname, name,spine_index,spine_faces,vertices_index_unique,vertices_center, vertices_head_index_set,vertices_neck_index_set,
  185. subsample_thre=None,
  186. f=None,
  187. N=None,
  188. num_chunks=None,
  189. num_points=None,
  190. line_num_points= None,
  191. line_num_points_inter= None,
  192. spline_smooth= None,
  193. ctl_run_thre=None,
  194. node_neck=None,
  195. node_head=None, ):
  196. metrics['head_diameter'][dname]= 2*metric_save[name]['limit'][0]
  197. metrics['neck_diameter'][dname]= 2*metric_save[name]['limit'][2]
  198. ctl_tmp=get_center_lines(
  199. vertices =self.vertices_00[spine_index],
  200. vertices_center= vertices_center,
  201. subsample_thre=subsample_thre,
  202. f=f,
  203. N=N,
  204. num_chunks=num_chunks,
  205. num_points=num_points,
  206. line_num_points= line_num_points,
  207. line_num_points_inter= line_num_points_inter,
  208. spline_smooth= spline_smooth,
  209. ctl_run_thre=ctl_run_thre,
  210. )
  211. metrics['spine_length'][dname] = Curve_length(ctl_tmp.vertices_center )
  212. metrics['head_length'][dname]=metrics['spine_length'][dname]
  213. head_index=list(set(spine_index).intersection(vertices_head_index_set))
  214. neck_index=list(set(spine_index).intersection(vertices_neck_index_set))
  215. metrics['spine_vol'][dname]=vol=volume(vertices=self.vertices_00[spine_index],faces=spine_faces)
  216. metrics['head_vol'][dname]= vol
  217. mesh=curv_mesh(vertices=self.vertices_00[spine_index],faces=spine_faces)
  218. mesh.Curvature()
  219. metrics['spine_area'][dname]=mesh.areas
  220. metrics['head_area'][dname]=mesh.areas
  221. vertices_index=spine_index
  222. facess=spine_faces
  223. neck_vertices_index=vertices_index_unique
  224. metrics['neck_vol'][dname]=0.
  225. metrics['neck_area'][dname]=0.
  226. metrics['neck_length'][dname]=0.
  227. if node_head is None:
  228. node_head=Branch_division(
  229. cclu=self.cclu,
  230. dend=self.dend,
  231. vertices_index=head_index,
  232. size_threshold= 2,
  233. )
  234. if len(node_head.children)<1:
  235. vertices_index=spine_index
  236. facess=spine_faces
  237. neck_vertices_index=vertices_index_unique
  238. neck_facess=facess
  239. else:
  240. if node_neck is None:
  241. node_neck=Branch_division(
  242. cclu=self.cclu,
  243. dend=self.dend,
  244. vertices_index=neck_index,
  245. size_threshold= 2,
  246. )
  247. if (node_neck.children is not None) and len(node_neck.children)>0:
  248. neck_vertices_index=node_neck.children[0].vertices_index
  249. neck_facess=node_neck.children[0].faces
  250. neck_vertices_index_unique=node_neck.children[0].vertices_index_unique
  251. metrics['neck_vol'][dname]=volume(vertices=self.vertices_00[neck_vertices_index],faces=neck_facess)
  252. mesh=curv_mesh(vertices=self.vertices_00[neck_vertices_index],faces=neck_facess)
  253. mesh.Curvature()
  254. metrics['neck_area'][dname]=mesh.areas
  255. ctl_tmp=get_center_lines(
  256. vertices =self.vertices_00[neck_vertices_index],
  257. vertices_center= vertices_center,
  258. subsample_thre=subsample_thre,
  259. f=f,
  260. N=N,
  261. num_chunks=num_chunks,
  262. num_points=num_points,
  263. line_num_points= line_num_points,
  264. line_num_points_inter= line_num_points_inter,
  265. spline_smooth= spline_smooth,
  266. ctl_run_thre=ctl_run_thre,
  267. )
  268. metrics['neck_length'][dname] = Curve_length(ctl_tmp.vertices_center )
  269. else:
  270. neck_vertices_index= vertices_index_unique
  271. neck_facess=vertices_index_unique
  272. neck_vertices_index_unique= vertices_index_unique
  273. if (node_head.children is not None) and len(node_head.children)>0:
  274. vertices_index=node_head.children[0].vertices_index
  275. facess=node_head.children[0].faces
  276. vertices_index_unique=node_head.children[0].vertices_index_unique
  277. metrics['head_vol'][dname]=volume(vertices=self.vertices_00[vertices_index],faces=facess)
  278. mesh=curv_mesh(vertices=self.vertices_00[vertices_index],faces=facess)
  279. mesh.Curvature()
  280. metrics['head_area'][dname]=mesh.areas
  281. ctl_tmp=get_center_lines(
  282. vertices =self.vertices_00[vertices_index],
  283. vertices_center= vertices_center,
  284. subsample_thre=subsample_thre,
  285. f=f,
  286. N=N,
  287. num_chunks=num_chunks,
  288. num_points=num_points,
  289. line_num_points= line_num_points,
  290. line_num_points_inter= line_num_points_inter,
  291. spline_smooth= spline_smooth,
  292. ctl_run_thre=ctl_run_thre,
  293. )
  294. metrics['head_length'][dname] = Curve_length(ctl_tmp.vertices_center )
  295. class pinn_data(pinn_data_init):
  296. def __init__(self, file_path_feat=None,
  297. dict_mesh_to_skeleton_finder_mesh=None,
  298. **kwargs):
  299. super().__init__(**kwargs)
  300. self.file_path_feat=file_path_feat
  301. self.dict_mesh_to_skeleton_finder_mesh=dict_mesh_to_skeleton_finder_mesh
  302. def get_annotation(self,
  303. dend_first_name=None,
  304. spine_path=None,
  305. shaft_path=None,
  306. file_path=None,
  307. dend_path_original_m=None,
  308. radius_threshold=None,
  309. disp_infos=None,
  310. size_threshold=None,
  311. file_path_feat=None,
  312. dend_path_original_new_smooth=None,
  313. dend_path_org_new=None,
  314. dend_name=None,
  315. ):
  316. disp_infos=disp_infos or self.disp_infos
  317. file_path = file_path or self.file_path
  318. file_path_feat = file_path_feat or self.file_path_feat
  319. spine_path = spine_path or self.spine_path
  320. shaft_path = shaft_path or self.shaft_path
  321. dend_path_original_m=dend_path_original_m or self.dend_path_original_m
  322. radius_threshold = radius_threshold or self.radius_threshold
  323. size_threshold=size_threshold or self.size_threshold
  324. dend_first_name=dend_first_name or self.dend_first_name
  325. if disp_infos:
  326. print(f"Annotation path original: {file_path}")
  327. print(f"Annotation path original dend_path_original_m: {dend_path_original_m}")
  328. from sklearn.neighbors import KDTree
  329. vertices_00 = np.loadtxt(os.path.join(file_path, self.txt_vertices_1), dtype=float)
  330. vertices_0 = np.loadtxt(os.path.join(file_path, self.txt_vertices_0), dtype=float)
  331. faces = np.loadtxt(os.path.join(file_path, self.txt_faces), dtype=int)
  332. os.makedirs( dend_path_org_new, exist_ok=True)
  333. mesh = trimesh.Trimesh(vertices=vertices_0, faces=faces)
  334. dend_nameu=dend_name or 'mesh'
  335. mesh.export(os.path.join(dend_path_original_new_smooth,f'{dend_nameu}.obj'))
  336. mesh = trimesh.Trimesh(vertices=vertices_00, faces=faces)
  337. dend_nameu=dend_name or 'mesh'
  338. mesh.export(os.path.join(dend_path_org_new,f'{dend_nameu}.obj'))
  339. self.mapp=mappings_vertices(vertices_0=vertices_00)
  340. if not os.path.exists(os.path.join(file_path_feat,self.pkl_vertex_neighbor)):
  341. dend = curv_mesh(vertices=vertices_00,
  342. faces=faces, )
  343. dend.Vertices_neighbor()
  344. with open(os.path.join(file_path_feat,self.pkl_vertex_neighbor), "wb") as file:
  345. pickle.dump(dend.vertex_neighbor, file)
  346. else:
  347. with open(os.path.join(file_path_feat,self.pkl_vertex_neighbor), 'rb') as f:
  348. vertex_neighbor = pickle.load(f)#
  349. dend = curv_mesh(vertices=vertices_00,
  350. faces=faces,
  351. vertex_neighbor=vertex_neighbor, )
  352. kdtree_00=KDTree(vertices_00)
  353. shaft=[]
  354. intensity_org=-20*np.ones_like(vertices_00[:,0:1])
  355. cclu=cluster_class(faces_neighbor_index= dend.vertex_neighbor)
  356. obj_indices = get_obj_filenames_with_indices_2(directory=dend_path_original_m,
  357. startwith=f'{dend_first_name}{self.name_spine_id}')
  358. if len(obj_indices)==0:
  359. return
  360. np.savetxt(os.path.join(spine_path,'spine_count_org.txt'),obj_indices, fmt='%s')
  361. vertices_index_appr_all=[]
  362. count=[]
  363. for ip,nam in enumerate(obj_indices):
  364. vertices_sp, _ = Obj_to_vertices(
  365. file_path_original= dend_path_original_m,
  366. mesh_name=nam,
  367. faces_new_mesh=False,
  368. save=False
  369. )
  370. vertices_index_appr=np.array(list(set(np.concatenate(kdtree_00.query_radius(vertices_sp,radius_threshold)))))
  371. print('vertices_index_appr',vertices_sp.shape,len(vertices_index_appr))
  372. if len(vertices_index_appr)> size_threshold:
  373. nodee=Branch_division(
  374. cclu=cclu,
  375. dend=dend,
  376. vertices_index=vertices_index_appr,
  377. size_threshold= size_threshold,
  378. stop_index=1 )
  379. vertices_index_appr_all.extend(nodee.children[0].vertices_index)
  380. if len(nodee.children)>0:
  381. vertices_index=nodee.children[0].vertices_index
  382. faces=nodee.children[0].faces
  383. vertices_index_unique=nodee.children[0].vertices_index_unique
  384. intensity_org[vertices_index ]=ip
  385. np.savetxt(os.path.join(spine_path, f'{self.name_spine_index}_{ip}.txt'), vertices_index, fmt='%d')
  386. np.savetxt(os.path.join(spine_path, f'{self.name_spine_faces}_{ip}.txt'), faces, fmt='%d')
  387. np.savetxt(os.path.join(spine_path, f'{self.name_spine_index_unique}_{ip}.txt'), vertices_index_unique, fmt='%d')
  388. count.append(ip)
  389. mesh=trimesh.Trimesh(vertices=vertices_00[vertices_index],faces=faces)
  390. mesh.export(os.path.join(dend_path_org_new,f'{dend_first_name}{self.name_spine_id}_{ip}.obj') )
  391. mesh=trimesh.Trimesh(vertices=vertices_0[vertices_index],faces=faces)
  392. mesh.export(os.path.join(dend_path_original_new_smooth,f'{dend_first_name}{self.name_spine_id}_{ip}.obj') )
  393. else:
  394. if disp_infos:
  395. print(obj_indices[ip],vertices_index_appr.shape)
  396. np.savetxt(os.path.join(spine_path,'spine_count.txt'),np.array(count), fmt='%d')
  397. vertices_index_shaft=np.array(list(set(np.arange(vertices_00.shape[0]))-set(vertices_index_appr_all)))
  398. np.savetxt(os.path.join(spine_path, self.txt_spine_intensity ), intensity_org, fmt='%d')
  399. if len(vertices_index_shaft)> size_threshold:
  400. nodee=Branch_division(
  401. cclu=cclu,
  402. dend=dend,
  403. vertices_index=vertices_index_shaft,
  404. size_threshold= size_threshold,
  405. stop_index=1 )
  406. if len(nodee.children)>0:
  407. vertices_index=nodee.children[0].vertices_index
  408. faces=nodee.children[0].faces
  409. vertices_index_unique=nodee.children[0].vertices_index_unique
  410. np.savetxt(os.path.join(shaft_path, self.txt_shaft_index), vertices_index, fmt='%d')
  411. np.savetxt(os.path.join(shaft_path, self.txt_shaft_faces), faces, fmt='%d')
  412. np.savetxt(os.path.join(shaft_path, self.txt_shaft_index_unique), vertices_index_unique, fmt='%d')
  413. mesh=trimesh.Trimesh(vertices=vertices_00[vertices_index],faces=faces)
  414. mesh.export(os.path.join(dend_path_org_new,f'{dend_first_name}{self.name_spine_id}_shaft.obj') )
  415. mesh=trimesh.Trimesh(vertices=vertices_0[vertices_index],faces=faces)
  416. mesh.export(os.path.join(dend_path_original_new_smooth,f'{dend_first_name}{self.name_spine_id}_shaft.obj') )
  417. def get_intensity_rhs(self,
  418. dend_first_name=None,
  419. spine_path=None,
  420. shaft_path=None,
  421. file_path=None,
  422. dend_path_original_m=None,
  423. radius_threshold=None,
  424. disp_infos=None,
  425. size_threshold=None,
  426. file_path_feat=None,
  427. ):
  428. disp_infos=disp_infos or self.disp_infos
  429. file_path = file_path or self.file_path
  430. file_path_feat=file_path_feat or self.file_path_feat
  431. spine_path = spine_path or self.spine_path
  432. shaft_path = shaft_path or self.shaft_path
  433. dend_path_original_m=dend_path_original_m or self.dend_path_original_m
  434. radius_threshold = radius_threshold or self.radius_threshold
  435. size_threshold=size_threshold or self.size_threshold
  436. dend_first_name=dend_first_name or self.dend_first_name
  437. if disp_infos:
  438. print(f"get_intensity_head_neck: {file_path}")
  439. vertices_00 = np.loadtxt(os.path.join(file_path, self.txt_vertices_1), dtype=float)
  440. intensity = np.zeros(vertices_00.shape[0])
  441. intensity_1hot=np.zeros_like(vertices_00[:,:-1],dtype=int)
  442. count= hff.loadtxt_count(os.path.join(spine_path,self.txt_spine_count))
  443. mmm=count.ndim
  444. spine_index_all=[]
  445. count=count if mmm==2 else count.reshape(-1,1)
  446. for i in range(count.shape[0]):
  447. ii=count[i,0]
  448. if ii <0:
  449. continue
  450. name=f'{ii}_{count[i,1]}' if mmm==2 else f'{count[i,0]}'
  451. spine_index = np.loadtxt(os.path.join(spine_path, f'{self.name_spine_index}_{name}.txt'),dtype=int)
  452. intensity[spine_index]=1
  453. spine_index_all.extend(spine_index)
  454. intensity_1hot[:,1:2][spine_index_all]=1
  455. intensity_1hot[:,0:1][list(set(np.arange(vertices_00.shape[0]))-set(spine_index_all))]=1
  456. np.savetxt(os.path.join(self.file_path_feat,'intensity_shaft_spine.txt'), intensity, fmt='%d')
  457. np.savetxt(os.path.join(self.file_path_feat,'intensity_1hot_shaft_spine.txt'), intensity_1hot, fmt='%d')
  458. def get_annotation_resized(self,
  459. file_path_resized,
  460. shaft_path_resized,
  461. dend_path_org_resized,
  462. dend_path_org_smooth_resized,
  463. dend_first_name=None,
  464. spine_path=None,
  465. shaft_path=None,
  466. file_path=None,
  467. file_path_feat=None,
  468. dend_path_original_m=None,
  469. radius_threshold=None,
  470. disp_infos=None,
  471. size_threshold=None,
  472. train_tf=None,
  473. thre_target_number_of_triangles=40000,
  474. min_target_number_of_triangles_faction=600000,
  475. target_number_of_triangles_faction=1000,
  476. voxel_resolution=2064,
  477. dict_mesh_to_skeleton_finder_mesh=None,
  478. dend_name=None,
  479. ):
  480. dict_mesh_to_skeleton_finder_mesh=dict_mesh_to_skeleton_finder_mesh or self.dict_mesh_to_skeleton_finder_mesh
  481. disp_infos=disp_infos or self.disp_infos
  482. file_path = file_path or self.file_path
  483. file_path_feat = file_path_feat or self.file_path_feat
  484. spine_path = spine_path or self.spine_path
  485. shaft_path = shaft_path or self.shaft_path
  486. dend_path_original_m=dend_path_original_m or self.dend_path_original_m
  487. radius_threshold = radius_threshold or self.radius_threshold
  488. size_threshold=size_threshold or self.size_threshold
  489. dend_first_name=dend_first_name or self.dend_first_name
  490. os.makedirs(file_path_resized, exist_ok=True)
  491. os.makedirs(shaft_path_resized, exist_ok=True)
  492. os.makedirs(os.path.join(file_path_resized,'feat'), exist_ok=True)
  493. os.makedirs( dend_path_org_resized, exist_ok=True)
  494. os.makedirs( dend_path_org_smooth_resized, exist_ok=True)
  495. if disp_infos:
  496. print(f"Annotation path original: {file_path}")
  497. print(f"================================= get_annotation_resized ====================================")
  498. vertices_00 = np.loadtxt(os.path.join(file_path, self.txt_vertices_1), dtype=float)
  499. n_vert=vertices_00.shape[0]
  500. vertices_0 = np.loadtxt(os.path.join(file_path, self.txt_vertices_0), dtype=float)
  501. faces = np.loadtxt(os.path.join(file_path, self.txt_faces), dtype=int)
  502. # target_number_of_triangles_faction=max(vertices_0.shape[0]//dict_mesh_to_skeleton_finder_mesh['target_number_of_triangles_faction'],
  503. # dict_mesh_to_skeleton_finder_mesh['min_target_number_of_triangles_faction'],)
  504. target_number_of_triangles_faction=max(vertices_0.shape[0]// target_number_of_triangles_faction, 2*min_target_number_of_triangles_faction)
  505. self.skl=skl=mesh_resize(vertices=vertices_00,
  506. faces=faces,
  507. target_number_of_triangles=target_number_of_triangles_faction ,)
  508. vertices_00 = skl.mesh.vertices
  509. vertices_0 = skl.reduce_rhs(vertices_0)
  510. faces = skl.mesh.faces
  511. mesh = trimesh.Trimesh(vertices=vertices_00, faces=faces)
  512. dend_nameu=dend_name or 'mesh'
  513. mesh.export(os.path.join(dend_path_org_resized,f'{dend_nameu}.obj'))
  514. np.savetxt(os.path.join(file_path_resized, self.txt_vertices_1), skl.mesh.vertices, fmt='%f')
  515. np.savetxt(os.path.join(file_path_resized, self.txt_faces), skl.mesh.faces, fmt='%d')
  516. np.savetxt(os.path.join(file_path_resized, self.txt_vertices_0), vertices_0 , fmt='%f')
  517. mesh=trimesh.Trimesh(vertices=vertices_0,faces=faces)
  518. mesh.export(os.path.join(dend_path_org_smooth_resized,f'{dend_name}.obj') )
  519. if os.path.exists(os.path.join(spine_path,'spine_count_org.txt')):
  520. if not os.path.exists(os.path.join(file_path_resized,self.pkl_vertex_neighbor)):
  521. dend = curv_mesh(vertices=vertices_00,
  522. faces=faces, )
  523. dend.Vertices_neighbor()
  524. vertex_neighbor=dend.vertex_neighbor
  525. with open(os.path.join(file_path_resized,self.pkl_vertex_neighbor), "wb") as file:
  526. pickle.dump(dend.vertex_neighbor, file)
  527. else:
  528. with open(os.path.join(file_path_resized,self.pkl_vertex_neighbor), 'rb') as f:
  529. vertex_neighbor = pickle.load(f)#
  530. dend = curv_mesh(vertices=vertices_00,
  531. faces=faces,
  532. vertex_neighbor=vertex_neighbor, )
  533. cclu=cluster_class(faces_neighbor_index= vertex_neighbor)
  534. shaft=[]
  535. intensity_org=-20*np.ones_like(vertices_00[:,0:1])
  536. obj_indices=np.loadtxt(os.path.join(spine_path,'spine_count_org.txt'),dtype=str,ndmin=1)
  537. np.savetxt(os.path.join(shaft_path_resized,'spine_count_org.txt'), obj_indices, fmt='%s')
  538. vertices_index_appr_all=[]
  539. count=[]
  540. for ip,nam in enumerate(obj_indices):
  541. if nam.endswith('shaft'):
  542. continue
  543. intensity_sp= np.zeros(n_vert)
  544. vertices_index=np.loadtxt(os.path.join(spine_path, f'{self.name_spine_index}_{ip}.txt'), dtype=int)
  545. intensity_sp[vertices_index]=1
  546. vertices_index= skl.reduce_rhs( intensity_sp).astype(int)
  547. vertices_index=np.where(vertices_index==1)[0]
  548. cclu.Cluster_index(ln_elm= vertices_index)
  549. cclu.Cluster_faces()
  550. cclu.Cluster_faces_unique()
  551. if len(cclu.cluster_index)>0:
  552. intensity_org[cclu.cluster_index ]=ip
  553. np.savetxt(os.path.join(shaft_path_resized, f'{self.name_spine_index}_{ip}.txt'), cclu.cluster_index, fmt='%d')
  554. np.savetxt(os.path.join(shaft_path_resized, f'{self.name_spine_faces}_{ip}.txt'), cclu.cluster_faces, fmt='%d')
  555. np.savetxt(os.path.join(shaft_path_resized, f'{self.name_spine_index_unique}_{ip}.txt'), cclu.cluster_faces_unique, fmt='%d')
  556. mesh=trimesh.Trimesh(vertices=vertices_00[cclu.cluster_index],faces=cclu.cluster_faces)
  557. mesh.export(os.path.join(dend_path_org_resized,f'{dend_first_name}{self.name_spine_id}_{ip}.obj') )
  558. mesh=trimesh.Trimesh(vertices=vertices_0[cclu.cluster_index],faces=cclu.cluster_faces)
  559. mesh.export(os.path.join(dend_path_org_smooth_resized,f'{dend_first_name}{self.name_spine_id}_{ip}.obj') )
  560. count.append(ip)
  561. vertices_index_appr_all.extend(cclu.cluster_index)
  562. np.savetxt(os.path.join(shaft_path_resized,'spine_count.txt'),np.array(count), fmt='%d')
  563. sett=set(np.arange(vertices_0.shape[0]))
  564. vertices_index_shaft=list(sett-set(vertices_index_appr_all).intersection(sett))
  565. np.savetxt(os.path.join(shaft_path_resized, self.txt_spine_intensity ), intensity_org, fmt='%d')
  566. if len(vertices_index_shaft)> size_threshold:
  567. cclu.Cluster_index(ln_elm= vertices_index_shaft)
  568. cclu.Cluster_faces()
  569. cclu.Cluster_faces_unique()
  570. np.savetxt(os.path.join(shaft_path_resized, self.txt_shaft_index), cclu.cluster_index, fmt='%d')
  571. np.savetxt(os.path.join(shaft_path_resized, self.txt_shaft_faces), cclu.cluster_faces, fmt='%d')
  572. np.savetxt(os.path.join(shaft_path_resized, self.txt_shaft_index_unique), cclu.cluster_faces_unique, fmt='%d')
  573. mesh=trimesh.Trimesh(vertices=vertices_00[cclu.cluster_index],faces=cclu.cluster_faces)
  574. mesh.export(os.path.join(dend_path_org_resized,f'{dend_first_name}_shaft.obj') )
  575. mesh=trimesh.Trimesh(vertices=vertices_0[cclu.cluster_index],faces=cclu.cluster_faces)
  576. mesh.export(os.path.join(dend_path_org_smooth_resized,f'{dend_first_name}_shaft.obj') )
  577. def get_pinn_features(self,
  578. feat_paths= None,
  579. base_features_list=None,
  580. file_path=None,
  581. file_path_feat=None,
  582. thre_gauss=None,
  583. thre_mean=None,
  584. head_neck=False,
  585. shaft_path_init=None,
  586. spine_path_init=None,
  587. ):
  588. add_feats=[]
  589. for vcv in feat_paths:
  590. if os.path.exists(vcv):
  591. add_feat=np.loadtxt(vcv)
  592. else:
  593. add_feat=None
  594. add_feats.append(add_feat)
  595. file_path = file_path or self.file_path
  596. file_path_feat = file_path_feat or self.file_path_feat
  597. thre_gauss=thre_gauss or self.thre_gauss
  598. thre_mean=thre_mean or self.thre_mean
  599. self.mean_curv= np.loadtxt(os.path.join(file_path_feat, self.txt_mean_curv_smooth), dtype=float)
  600. self.gauss_curv= np.loadtxt(os.path.join(file_path_feat, self.txt_gauss_curv_smooth), dtype=float)
  601. self.skl_curv= np.loadtxt(os.path.join(file_path_feat, self.txt_skl_distance), dtype=float)
  602. # self.skl_curv_con= np.loadtxt(os.path.join(file_path_feat, self.txt_skl_distance_con), dtype=float)
  603. # self.skl_curv_imp_con = Impute_intensity(self.skl_curv_con)
  604. self.skl_curv_imp =skl_curv_imp= Impute_intensity(self.skl_curv)
  605. self.mean_curv_imp=mean_curv_imp=Threshold_curv(curv=Impute_intensity(self.mean_curv) , thre=thre_mean)
  606. self.gauss_curv_imp=gauss_curv_imp=Threshold_curv(curv=Impute_intensity(self.gauss_curv) ,thre=thre_gauss)
  607. self.mean_sq_curv =np.loadtxt(os.path.join(file_path_feat, self.txt_mean_sq_curv_smooth), dtype=float)
  608. self.gauss_sq_curv =np.loadtxt(os.path.join(file_path_feat, self.txt_gauss_sq_curv_smooth), dtype=float)
  609. self.mean_sq_curv_imp=Threshold_curv(curv=Impute_intensity(self.mean_sq_curv), thre=thre_mean)
  610. self.gauss_sq_curv_imp=Threshold_curv(curv=Impute_intensity(self.gauss_sq_curv),thre=thre_gauss)
  611. self.skl_curv_org= np.loadtxt(os.path.join(file_path_feat, 'skl_distance_org.txt'), dtype=float)
  612. self.skl_curv_imp_org = Impute_intensity(self.skl_curv_org)
  613. self.mean_curv_init =np.loadtxt(os.path.join(file_path_feat, self.txt_mean_curv_init), dtype=float)
  614. self.gauss_curv_init=np.loadtxt(os.path.join(file_path_feat, self.txt_gauss_curv_init), dtype=float)
  615. self.mean_curv_init_imp=Threshold_curv(curv=Impute_intensity(self.mean_curv_init) , thre=thre_mean)
  616. self.gauss_curv_init_imp=Threshold_curv(curv=Impute_intensity(self.gauss_curv_init) , thre=thre_mean)
  617. mean_sq_curv_init =np.loadtxt(os.path.join(file_path_feat, self.txt_mean_sq_curv_init), dtype=float)
  618. gauss_sq_curv_init =np.loadtxt(os.path.join(file_path_feat, self.txt_gauss_sq_curv_init), dtype=float)
  619. self.mean_sq_curv_init_imp=Threshold_curv(curv=Impute_intensity(mean_sq_curv_init), thre=thre_mean)
  620. self.gauss_sq_curv_init_imp=Threshold_curv(curv=Impute_intensity(gauss_sq_curv_init),thre=thre_gauss)
  621. curv_k=mean_curv_imp+np.abs(mean_curv_imp**2-gauss_curv_imp)**(1/2)
  622. curv_v=mean_curv_imp-np.abs(mean_curv_imp**2-gauss_curv_imp)**(1/2)
  623. self.base_features_dict['curv_k']['values']=curv_k
  624. self.base_features_dict['curv_v']['values']=curv_v
  625. self.base_features_dict['curv_k2']['values']=curv_k**2
  626. self.base_features_dict['curv_v2']['values']=curv_v**2
  627. self.base_features_dict['curv_kv']['values']=curv_v*curv_k
  628. self.base_features_dict['curv_kv22']['values']=(curv_v*curv_k)**2
  629. self.base_features_dict['gauss']['values']=gauss_curv_imp
  630. self.base_features_dict['mean']['values']=mean_curv_imp
  631. self.base_features_dict['gauss_sq']['values']=self.gauss_sq_curv_imp #gauss_curv_imp**2#
  632. self.base_features_dict['mean_sq']['values']=self.mean_sq_curv_imp #mean_curv_imp**2#
  633. self.base_features_dict['gauss_qd']['values']=gauss_curv_imp**4
  634. self.base_features_dict['mean_qd']['values']=mean_curv_imp**4
  635. self.base_features_dict['igauss']['values']=self.gauss_curv_init_imp
  636. self.base_features_dict['imean']['values']=self.mean_curv_init_imp
  637. self.base_features_dict['igauss_sq']['values']=self.gauss_sq_curv_init_imp
  638. self.base_features_dict['imean_sq']['values']=self.mean_sq_curv_init_imp
  639. self.base_features_dict['skl']['values']=hff.normalize( (skl_curv_imp))
  640. for rf in self.kmean_list:
  641. self.base_features_dict[f'kmean_{rf}']['values']= get_kmean(skl_curv_imp,n_clusters=rf,kmean_max_iter=600).reshape(-1,1)
  642. for rf in self.kmean_list:
  643. self.base_features_dict[f'kmean_mean_{rf}']['values']= get_kmean(self.skl_curv_imp_org,n_clusters=rf,kmean_max_iter=600).reshape(-1,1)
  644. if base_features_list is not None:
  645. base_featuress=base_features_list
  646. else:
  647. base_featuress=self.base_features_dict.keys()
  648. base_features=[]
  649. for ii in base_featuress:
  650. ngn=self.base_features_dict[ii]['values']
  651. base_features.append(ngn)
  652. patr=os.path.join(self.file_path_feat,f'{ii}.txt')
  653. for ii in self.base_features_dict.keys():
  654. ngn=self.base_features_dict[ii]['values']
  655. patr=os.path.join(self.file_path_feat,f'{ii}.txt')
  656. np.savetxt(patr,ngn,fmt='%f')
  657. for add_feat in add_feats:
  658. if add_feat is not None:
  659. base_features= get_model(base_features= base_features,
  660. vcv_length=add_feat,
  661. model_sufix=self.model_sufix)
  662. else:
  663. print(f'I activated {self.model_sufix}')
  664. return base_features
  665. def get_central_data(
  666. self,
  667. line_num_points_shaft=None,
  668. line_num_points_inter_shaft=None,
  669. spline_smooth_shaft=None,
  670. shaft_path=None,
  671. ctl_run_thre=1,
  672. smooth_tf=False,
  673. vertices_center=None,
  674. ):
  675. dend=self.dend
  676. shaft_path=shaft_path or self.shaft_path_pre or self.shaft_path
  677. line_num_points_shaft=line_num_points_shaft or self.line_num_points_shaft
  678. line_num_points_inter_shaft=line_num_points_inter_shaft or self.line_num_points_inter_shaft
  679. spline_smooth_shaft=spline_smooth_shaft or self.spline_smooth_shaft
  680. # vertices_index_shaft=shaft_index=spn.children[0].vertices_index
  681. print('shaft_path----------->>>>>>. get_central_data----------->>>>>>.',shaft_path)
  682. # print('spline_smooth_shaft',spline_smooth_shaft)
  683. vertices_0=dend.vertices
  684. vcv_length_path=os.path.join( shaft_path, self.txt_shaft_vcv_length)
  685. vertices_center_path=os.path.join( shaft_path, self.txt_shaft_vertices_center)
  686. # print('vcv destination----------->>>>>>.',vcv_length_path)
  687. # if not (os.path.exists(vertices_center_path) and os.path.exists(vcv_length_path)):
  688. vertices_00 = np.loadtxt(os.path.join(self.file_path, self.txt_vertices_1), dtype=float)
  689. self.mapp=mappings_vertices(vertices_0=dend.vertices)
  690. self.kdtree=KDTree(vertices_0)
  691. self.cclu=cluster_class(faces_neighbor_index=dend.vertex_neighbor)
  692. if os.path.exists(os.path.join(shaft_path, self.txt_shaft_index)):
  693. shaft_index = np.loadtxt(os.path.join(shaft_path, self.txt_shaft_index), dtype=int)
  694. # faces = np.loadtxt(os.path.join(shaft_path, self.txt_faces), dtype=int)
  695. # if not os.path.exists(vertices_center_path):
  696. # return
  697. line_num_points_shaft = max(vertices_00.shape[0] // line_num_points_shaft, 10)
  698. print('line_num_points_shaft----------->>>>>>.[[]]',line_num_points_shaft,line_num_points_inter_shaft,spline_smooth_shaft)
  699. if vertices_center is not None:
  700. # if not (os.path.exists(vcv_length_path) and os.path.exists(vertices_center_path)):
  701. ctl = center_curvature(vertices=vertices_center,
  702. line_num_points=line_num_points_shaft,
  703. line_num_points_inter=line_num_points_inter_shaft,
  704. spline_smooth=spline_smooth_shaft,
  705. smooth_tf=smooth_tf,)
  706. np.savetxt(vcv_length_path, ctl.vcv_length, fmt='%f')
  707. self.vcv_length= np.loadtxt(vcv_length_path,ndmin=1)
  708. np.savetxt(vertices_center_path, ctl.vertices_center, fmt='%f')
  709. print('=========== im in',vcv_length_path)
  710. # else:
  711. # ctl = center_curvature(vertices=vertices_00,
  712. # vertices_index=shaft_index,
  713. # line_num_points=line_num_points_shaft,
  714. # line_num_points_inter=line_num_points_inter_shaft,
  715. # spline_smooth=spline_smooth_shaft,
  716. # smooth_tf=smooth_tf,)
  717. self.shaft_index=shaft_index=np.loadtxt(os.path.join( shaft_path, self.txt_shaft_index),dtype=int)
  718. self.vertices_center = np.loadtxt(vertices_center_path)
  719. self.vcv_length= np.loadtxt(vcv_length_path,ndmin=1)
  720. self.clu_pca=clust_pca(vertices_0,shaft_index,
  721. vertices_center= self.vertices_center,
  722. vcv_length=self.vcv_length)
  723. print('shaft_path----------->>>>>>. get_central_data----------->>>>>>.DONE' )
  724. def save_pinn_data(self,
  725. file_path=None,
  726. file_path_feat=None,
  727. spine_path=None,
  728. shaft_path=None,
  729. thre_gen=None,
  730. thre_target_number_of_triangles=None,
  731. voxel_resolution =None,
  732. dict_mesh_to_skeleton_finder_mesh=None,
  733. ):
  734. file_path = file_path or self.file_path
  735. file_path_feat = file_path_feat or self.file_path_feat
  736. shaft_path=shaft_path or self.shaft_path
  737. spine_path=spine_path or self.spine_path
  738. thre_gen=thre_gen or self.thre_gen
  739. thre_target_number_of_triangles=thre_target_number_of_triangles or self.thre_target_number_of_triangles
  740. dict_mesh_to_skeleton_finder_mesh=dict_mesh_to_skeleton_finder_mesh or self.dict_mesh_to_skeleton_finder_mesh
  741. print('self.file_path',self.file_path)
  742. voxel_resolution=voxel_resolution or self.voxel_resolution
  743. self.vertices_00 =vertices_00 = np.loadtxt(os.path.join(file_path, self.txt_vertices_1), dtype=float)
  744. faces = np.loadtxt(os.path.join(file_path, self.txt_faces), dtype=int)
  745. dend = curv_mesh(vertices=vertices_00, faces=faces)
  746. dend.Gauss_curv()
  747. dend.Mean_curv()
  748. gauss_curv=Threshold_curv(curv=dend.gauss_curv,thre=thre_gen)
  749. mean_curv=Threshold_curv(curv=dend.mean_curv,thre=thre_gen)
  750. gauss_sq_curv=Threshold_curv(curv=dend.gauss_curv*dend.gauss_curv,thre=thre_gen)
  751. mean_sq_curv=Threshold_curv(curv=dend.mean_curv*dend.mean_curv,thre=thre_gen)
  752. np.savetxt(os.path.join(file_path_feat, self.txt_gauss_curv_init),gauss_curv, fmt='%f')
  753. np.savetxt(os.path.join(file_path_feat, self.txt_mean_curv_init),mean_curv, fmt='%f')
  754. gauss_sq_curv=Threshold_curv(curv=dend.gauss_curv*dend.gauss_curv,thre=thre_gen)
  755. mean_sq_curv=Threshold_curv(curv=dend.mean_curv*dend.mean_curv,thre=thre_gen)
  756. np.savetxt(os.path.join(file_path_feat, self.txt_gauss_sq_curv_init),gauss_sq_curv, fmt='%f')
  757. np.savetxt(os.path.join(file_path_feat, self.txt_mean_sq_curv_init),mean_sq_curv, fmt='%f')
  758. # np.savetxt(os.path.join(file_path, self.txt_faces_class_faces), faces_class_faces, fmt='%d')
  759. # np.savetxt(os.path.join(file_path, self.txt_vertex_neighbor),vertex_neighbor, fmt='%d')
  760. vertices_0 = np.loadtxt(os.path.join(file_path, self.txt_vertices_0), dtype=float)
  761. # vertices_0 -= np.mean(vertices_0, axis=0)
  762. dend = curv_mesh(vertices=vertices_0, faces=faces )
  763. if not os.path.exists(os.path.join(file_path_feat,self.pkl_vertex_neighbor)):
  764. dend.Vertices_neighbor()
  765. with open(os.path.join(file_path_feat,self.pkl_vertex_neighbor), "wb") as file:
  766. pickle.dump(dend.vertex_neighbor, file)
  767. else:
  768. with open(os.path.join(file_path_feat,self.pkl_vertex_neighbor) , "rb") as file:
  769. dend.vertex_neighbor=pickle.load(file)
  770. # if not os.path.exists(os.path.join(file_path, self.txt_gauss_curv_smooth)):
  771. # if os.path.exists(os.path.join(file_path, self.txt_vertices_0)):
  772. dend.Gauss_curv()
  773. dend.Mean_curv()
  774. self.dend=dend
  775. gauss_curv=Threshold_curv(curv=dend.gauss_curv,thre=thre_gen)
  776. mean_curv=Threshold_curv(curv=dend.mean_curv,thre=thre_gen)
  777. np.savetxt(os.path.join(file_path_feat, self.txt_gauss_curv_smooth),gauss_curv, fmt='%f')
  778. np.savetxt(os.path.join(file_path_feat, self.txt_mean_curv_smooth),mean_curv, fmt='%f')
  779. gauss_sq_curv=Threshold_curv(curv=dend.gauss_curv*dend.gauss_curv,thre=thre_gen)
  780. mean_sq_curv=Threshold_curv(curv=dend.mean_curv*dend.mean_curv,thre=thre_gen)
  781. np.savetxt(os.path.join(file_path_feat, self.txt_gauss_sq_curv_smooth),gauss_sq_curv, fmt='%f')
  782. np.savetxt(os.path.join(file_path_feat, self.txt_mean_sq_curv_smooth),mean_sq_curv, fmt='%f')
  783. if not os.path.exists(os.path.join(file_path_feat, self.txt_skl_distance)):
  784. self.skl=skl=def_mesh_to_skeleton_finder(vertices=vertices_0,
  785. faces=faces,
  786. ** dict_mesh_to_skeleton_finder_mesh,
  787. )
  788. #
  789. np.savetxt(os.path.join(file_path_feat, self.txt_skl_vectices),skl.skeleton_points, fmt='%f')
  790. np.savetxt(os.path.join(file_path_feat, self.txt_skl_distance),skl.distances, fmt='%f')
  791. np.savetxt(os.path.join(file_path_feat, self.txt_skl_index),skl.skl_index, fmt='%d')
  792. if not os.path.exists(os.path.join(file_path_feat, self.txt_skl_distance_org)):
  793. vertices_00 = np.loadtxt(os.path.join(file_path, self.txt_vertices_1), dtype=float)
  794. skl=def_mesh_to_skeleton_finder(vertices=vertices_00,
  795. faces=faces,
  796. ** dict_mesh_to_skeleton_finder_mesh,
  797. )
  798. np.savetxt(os.path.join(file_path_feat, self.txt_skl_vectices_org),skl.skeleton_points, fmt='%f')
  799. np.savetxt(os.path.join(file_path_feat, self.txt_skl_distance_org),skl.distances, fmt='%f')
  800. np.savetxt(os.path.join(file_path_feat, self.txt_skl_index_org),skl.skl_index, fmt='%d')
  801. def get_shaft_pred(self,
  802. rhs,
  803. path_train,
  804. pre_portion=None,
  805. weight=None,
  806. weights=None,
  807. seg_dend='full',
  808. zoom_thre=25,
  809. skip_first_n=1,
  810. skip_mid_n=None,
  811. skip_end_n=10,
  812. subdivision_thre=3,
  813. subsample_thre=.02,
  814. f=0.99,
  815. N=10,
  816. num_chunks=100,
  817. line_num_points=None,
  818. line_num_points_inter=None,
  819. spline_smooth=None,
  820. num_points=50,
  821. ctl_run_thre=0,
  822. size_threshold=None ,
  823. end_thre=40,
  824. get_refine_=False,
  825. dest_path='dest_spine_path',
  826. spine_fraction=3,
  827. shaft_thre=1/4,
  828. gauss_threshold=10,
  829. smooth_tf=False,
  830. neck_lim=0,
  831. get_data_txt=True,
  832. reconstruction_tf=False,
  833. dict_mesh_to_skeleton_finder=None,
  834. dict_wrap=None,
  835. file_path_feat=None,
  836. tf_skl_shaft_distance=False,
  837. ):
  838. file_path_feat = file_path_feat or self.file_path_feat
  839. line_num_points=line_num_points or self.line_num_points_shaft
  840. line_num_points_inter=line_num_points_inter or self.line_num_points_inter_shaft
  841. spline_smooth=spline_smooth or self.spline_smooth_shaft
  842. data_shaft_path=self.path_file[path_train['data_spine_path']]
  843. dest_shaft_path=self.path_file[path_train['dest_shaft_path']]
  844. shaft_path = self.path_file[path_train['dest_shaft_path']]
  845. spine_path_new=self.path_file[path_train['dest_spine_path']]
  846. spine_path = self.path_file[path_train['dest_spine_path']]
  847. spine_path_new_pre=self.path_file[path_train['dest_spine_path_pre']]
  848. shaft_vertices_center_path=self.path_file[self.path_train['data_shaft_path']]
  849. shaft_vertices_center_path_dest=self.path_file[path_train['dest_spine_path_center']]
  850. dest_spine_path_new=self.path_file[path_train[dest_path]]
  851. pre_save_txt= False if dest_path=='dest_spine_path_pre' else True
  852. size_threshold=size_threshold or self.size_threshold
  853. skl_vertices=np.loadtxt(os.path.join(self.file_path_feat, self.txt_skl_vectices),dtype=float)
  854. skl_index=np.loadtxt(os.path.join(self.file_path_feat, self.txt_skl_index),dtype=int)
  855. inten=-1*np.ones_like(rhs[:,0])
  856. if weight is None:
  857. siz=rhs.shape[1]
  858. weight=1/siz*np.ones(siz)
  859. dend=self.dend
  860. rhs0=np.array([weight,0.81])*rhs.copy()
  861. msh_tmp=model_shaft(dend,rhs0, stop_index=1,size_threshold=size_threshold,shaft_thre=shaft_thre,uniq_rem_lim=neck_lim)
  862. msh_tmp.get_spine_node()
  863. masa_tmp=len(msh_tmp.node_spine.children)
  864. msh=msh_tmp
  865. print(f'get_shaft_pred: -- Weight {weight}| Spine Total Number = {masa_tmp}| size_threshold = {size_threshold}')
  866. self.msh=msh
  867. shaft_index=msh.shaft_index
  868. shaft_faces=msh.shaft_faces
  869. shaft_index_unique=msh.shaft_index_unique
  870. if get_data_txt:
  871. predicted_labels=msh.rhs_vals
  872. for label in range(rhs.shape[1]):
  873. self.vertices_approx_index=vertices_approx_index = np.where(predicted_labels == label)[0]
  874. inten[vertices_approx_index]=label
  875. cluster = np.ones(dend.n_vert )
  876. cluster[msh.shaft_index]=0
  877. intensity_spines_cluster=msh.rhs_vals
  878. dest_spine_path_pre_init=self.path_file[path_train['dest_spine_path_pre_init']]
  879. np.savetxt(os.path.join(spine_path,f'intensity_{pre_portion}_segm.txt'), inten, fmt='%d')
  880. np.savetxt(os.path.join(shaft_path,f'intensity_{pre_portion}_segm.txt'), inten, fmt='%d')
  881. np.savetxt(os.path.join( dest_spine_path_pre_init,f'intensity_{pre_portion}_segm.txt'),inten, fmt='%d')
  882. np.savetxt(os.path.join(spine_path, 'intensity_spines_segment_shaft.txt'), cluster, fmt='%d')
  883. np.savetxt(os.path.join(shaft_path, 'intensity_spines_segment_shaft.txt'), cluster, fmt='%d')
  884. np.savetxt(os.path.join(spine_path, self.txt_shaft_index), shaft_index, fmt='%d')
  885. np.savetxt(os.path.join(spine_path, self.txt_shaft_faces), shaft_faces, fmt='%d')
  886. np.savetxt(os.path.join(spine_path, self.txt_shaft_index_unique), shaft_index_unique, fmt='%d')
  887. np.savetxt(os.path.join(shaft_path, self.txt_shaft_index), shaft_index, fmt='%d')
  888. np.savetxt(os.path.join(shaft_path, self.txt_shaft_faces), shaft_faces, fmt='%d')
  889. np.savetxt(os.path.join(shaft_path, self.txt_shaft_index_unique), shaft_index_unique, fmt='%d')
  890. skl_vertices=np.loadtxt(os.path.join(self.file_path_feat, self.txt_skl_vectices),dtype=float)
  891. skl_index=np.loadtxt(os.path.join(self.file_path_feat, self.txt_skl_index),dtype=int)
  892. self.get_central_data(shaft_path=shaft_path,
  893. smooth_tf=smooth_tf,
  894. vertices_center=skl_vertices[skl_index[shaft_index]])
  895. nodevv=msh.node_spine
  896. node_io=dendrite_io(txt_save_file=spine_path,
  897. shaft_index=shaft_index,
  898. name=self,
  899. itera_start=0,
  900. vertices_index=np.arange(self.dend.n_vert,dtype=int),
  901. faces=self.dend.faces,
  902. skl_vertices=skl_vertices,
  903. skl_index=skl_index,
  904. size_threshold=size_threshold,)
  905. node_io.node_to_txt(node=nodevv, intensity_len=dend.n_vert, part=self.name_spine)
  906. node_io=dendrite_io(txt_save_file=shaft_path,
  907. shaft_index=shaft_index ,
  908. name=self,
  909. itera_start=0,
  910. vertices_index=np.arange(self.dend.n_vert,dtype=int),
  911. faces=self.dend.faces,
  912. skl_vertices=skl_vertices,
  913. skl_index=skl_index,
  914. size_threshold=size_threshold,)
  915. node_io.node_to_txt(node=nodevv, intensity_len=dend.n_vert, part=self.name_spine)
  916. np.savetxt(os.path.join(shaft_path, self.txt_intensity_spines_segment), intensity_spines_cluster, fmt='%d')
  917. np.savetxt(os.path.join(shaft_vertices_center_path, self.txt_shaft_vertices_center), self.vertices_center, fmt='%f')
  918. np.savetxt(os.path.join(shaft_vertices_center_path, self.txt_shaft_index), shaft_index, fmt='%d')
  919. np.savetxt(os.path.join(shaft_vertices_center_path, self.txt_shaft_faces), shaft_faces, fmt='%d')
  920. np.savetxt(os.path.join(shaft_vertices_center_path, self.txt_shaft_index), shaft_index, fmt='%d')
  921. np.savetxt(os.path.join(shaft_vertices_center_path, self.txt_shaft_faces), shaft_faces, fmt='%d')
  922. np.savetxt(os.path.join(shaft_vertices_center_path_dest, self.txt_shaft_vertices_center), self.vertices_center, fmt='%f')
  923. np.savetxt(os.path.join(shaft_vertices_center_path_dest, self.txt_shaft_vcv_length), self.vcv_length, fmt='%f')
  924. np.savetxt(os.path.join(shaft_path, self.txt_shaft_vcv_length), self.vcv_length, fmt='%f')
  925. np.savetxt(os.path.join(shaft_path , self.txt_shaft_vertices_center), self.vertices_center, fmt='%f')
  926. np.savetxt(os.path.join(file_path_feat, self.txt_shaft_vcv_length), self.vcv_length, fmt='%f')
  927. np.savetxt(os.path.join(file_path_feat , self.txt_shaft_vertices_center), self.vertices_center, fmt='%f')
  928. np.savetxt(os.path.join(spine_path_new , 'shaft_vcv_length.txt'), self.vcv_length, fmt='%f')
  929. if tf_skl_shaft_distance and (dict_mesh_to_skeleton_finder is not None):
  930. if not os.path.exists(os.path.join(file_path_feat, self.txt_skl_shaft_vectices)):
  931. vertices_00 = np.loadtxt(os.path.join(self.file_path, self.txt_vertices_1), dtype=float)
  932. vertices_0 = np.loadtxt(os.path.join(self.file_path, self.txt_vertices_0), dtype=float)
  933. simplified_vertices,simplified_faces=get_wrap(vertices=vertices_0[shaft_index],
  934. faces=shaft_faces,
  935. **dict_wrap,
  936. )
  937. mesh = trimesh.Trimesh(vertices=simplified_vertices, faces=simplified_faces)
  938. mesh.export(os.path.join(file_path_feat,'mesh_wrap.obj'))
  939. nskl=def_mesh_to_skeleton_finder(vertices=simplified_vertices,
  940. faces=simplified_faces,
  941. ** dict_mesh_to_skeleton_finder,
  942. )
  943. skeleton_p,_,_=order_points_along_pca(nskl.skeleton_points)
  944. np.savetxt(os.path.join(file_path_feat, self.txt_skl_shaft_vectices),skeleton_p, fmt='%f')
  945. tree = KDTree(skeleton_p)
  946. dist, _= tree.query(vertices_00 )
  947. np.savetxt(os.path.join(file_path_feat, self.txt_skl_shaft_distance),dist, fmt='%f')
  948. def get_head_neck_segss(self,
  949. spine_shaft_txt,
  950. path_train,
  951. metrics,
  952. seg_dend='full',
  953. pre_portion=None,
  954. zoom_thre=25,
  955. skip_first_n=1,
  956. skip_end_n=10,
  957. subdivision_thre=3,
  958. subsample_thre=.02,
  959. f=0.99,
  960. N=10,
  961. num_chunks=100,
  962. line_num_points=None,
  963. line_num_points_inter=None,
  964. spline_smooth=None,
  965. num_points=50,
  966. ctl_run_thre=1,
  967. size_threshold=None ,
  968. end_thre=40,
  969. get_refine_=False,
  970. head_neck_path='dest_spine_path',
  971. smooth_tf=False,
  972. dict_mesh_to_skeleton_finder_mesh=None,
  973. ):
  974. line_num_points=line_num_points or self.line_num_points_shaft
  975. line_num_points_inter=line_num_points_inter or self.line_num_points_inter_shaft
  976. spline_smooth=spline_smooth or self.spline_smooth_shaft
  977. data_shaft_path=self.path_file[path_train['data_spine_path']]
  978. dest_shaft_path=self.path_file[path_train['dest_shaft_path']]
  979. spine_path_new_pre=self.path_file[path_train['dest_spine_path_pre']]
  980. shaft_vertices_center_path=self.path_file[path_train['data_spine_path_center']]
  981. shaft_vertices_center_path_dest=self.path_file[path_train['dest_spine_path_center']]
  982. dest_spine_path_pre_init=self.path_file[path_train['dest_spine_path_pre_init']]
  983. spine_path_new=dest_spine_path_new=self.path_file[path_train[head_neck_path]]
  984. pre_save_txt= False if head_neck_path=='dest_spine_path_pre' else True
  985. self.get_dend_data()
  986. dist_norm=dist_norm_gen=np.loadtxt(os.path.join(self.file_path_feat, self.txt_skl_distance))
  987. n_vert=len(dist_norm_gen)
  988. dist_norm=np.loadtxt(os.path.join(self.file_path_feat, f'kmean_4.txt')).astype(int)
  989. intensity_org_neck_head = np.zeros(n_vert)
  990. intensity_pca={}
  991. self.metric_save={}
  992. for key in self.inten_pca:
  993. intensity_pca[key]=np.zeros(n_vert)
  994. skl_vectices= np.loadtxt(os.path.join(self.file_path_feat, f'skl_vectices.txt'),dtype=float)
  995. inten=np.loadtxt(os.path.join(self.file_path_feat, f'kmean_10.txt')).astype(int)
  996. reg=region_branch(region_index=inten,dend=self.dend,skl_vectices=skl_vectices)
  997. reg.get_skl_smooth(
  998. line_num_points=10,
  999. line_num_points_inter=30,
  1000. spline_smooth=0.75)
  1001. count= hff.loadtxt_count(os.path.join(spine_path_new,self.txt_spine_count))
  1002. mmm=count.ndim
  1003. count=count if mmm==2 else count.reshape(-1,1)
  1004. for idx in range(count.shape[0]):
  1005. ii=count[idx,0]
  1006. name=f'{ii}_{count[idx,1]}' if mmm==2 else f'{ii}'
  1007. dname=f'{self.dend_first_name}_sy{name}'
  1008. if ii<0:
  1009. name=f'0_0'
  1010. dname=f'{self.dend_first_name}_sy{name}'
  1011. spine_index=self.dend.vertices
  1012. spine_faces=self.dend.faces
  1013. np.savetxt(os.path.join(spine_path_new, f'{self.name_spine}_{self.name_index}_{name}.txt'), spine_index, fmt='%d')
  1014. np.savetxt(os.path.join(spine_path_new, f'{self.name_spine}_{self.name_faces}_{name}.txt'), spine_faces, fmt='%d')
  1015. np.savetxt(os.path.join(spine_path_new, f'spine_{self.name_count}.txt'), [[0,0]], fmt='%d')
  1016. else:
  1017. spine_index = np.loadtxt(os.path.join(spine_path_new, f'{self.name_spine}_{self.name_index}_{name}.txt'),dtype=int)
  1018. spine_faces = np.loadtxt(os.path.join(spine_path_new, f'{self.name_spine}_{self.name_faces}_{name}.txt'),dtype=int)
  1019. vertices_index_unique=np.loadtxt(os.path.join(spine_path_new, f'{self.name_spine_index_unique}_{name}.txt'),dtype=int)
  1020. loo=os.path.join( spine_path_new,f'{self.name_spine}_{self.name_center}_curv_{name}.txt')
  1021. if os.path.exists(loo):
  1022. vertices_center=np.loadtxt(loo,dtype=float)
  1023. else:
  1024. continue
  1025. vecty=dist_norm[spine_index]
  1026. vectyy=reg.intensity_thickness[spine_index]
  1027. arg_ver=np.argsort(vecty)
  1028. bvg=2*np.ones(len(spine_index))
  1029. bvg[vecty<=vecty[arg_ver[1]]]=1
  1030. intensity_org_neck_head[spine_index]=bvg
  1031. self.metric_save[name]={}
  1032. self.metric_save[name]['limit']=(0,0,0,0) if len(vectyy)<=0 else find_min_max_no_cross(vectyy)
  1033. vertices_head_index_set = set(np.where(intensity_org_neck_head == 2)[0])
  1034. vertices_neck_index_set = set(np.where(intensity_org_neck_head == 1)[0])
  1035. if (len(vertices_center)>3) and (len(spine_index)>0):
  1036. get_head_neck_mectric(self,self.metric_save,metrics,dname, name,spine_index,spine_faces,vertices_index_unique,vertices_center, vertices_head_index_set,vertices_neck_index_set,
  1037. subsample_thre=subsample_thre,
  1038. f=f,
  1039. N=N,
  1040. num_chunks=num_chunks,
  1041. num_points=num_points,
  1042. line_num_points= line_num_points,
  1043. line_num_points_inter= line_num_points_inter,
  1044. spline_smooth= spline_smooth,
  1045. ctl_run_thre=ctl_run_thre,
  1046. # node_head=node_head,
  1047. # node_neck=node_neck,
  1048. )
  1049. np.savetxt(os.path.join(spine_path_new, 'intensity_head_neck_segm.txt'),intensity_org_neck_head,fmt='%d')

help_pinn_data_222.py at commit 6dcc0e8, no license · at the source

Overview

Authors: Abdel Kader A Geraldo1, Michael A Chirillo2, Kristen M Harris3, Thomas G Fai4
ORCID iDs: Thomas G Fai
  1. Department of Mathematics, Brandeis University, Waltham, MA, USA
  2. Department of Biological Sciences, University of Rhode Island, Kingston, RI, USA
  3. Department of Neuroscience, University of Texas at Austin, Austin, TX, USA
  4. Department of Mathematics and Volen Center for Complex Systems, Brandeis University, Waltham, MA, USA
Institutions: Brandeis University (United States); University of Rhode Island (United States); The University of Texas at Austin (United States)
Journal: Biophysical journal, volume 125, issue 14, pages 3604-3619
Dates: received 29 December 2025; accepted 2 June 2026; published online 5 June 2026; in print 21 July 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1016/j.bpj.2026.06.005 · PMID 42249612 · PMCID PMC13335156 · OpenAlex W7163635577
Open access: hybrid, a free copy (OpenAlex)
Status: code verified
Categories: histology / microscopy (modality)
Methods: Smoothing, state filtering, decompositions, Machine learning
MeSH: Dendritic Spines*, Imaging, Three-Dimensional*, Machine Learning*, Animals, Automation (* major topic)
Topic: Medical Imaging and Analysis (Biomedical Engineering, Engineering), according to OpenAlex
Funding: NIMH NIH HHS (R56 MH139176, R01 MH095980); NINDS NIH HHS (T32 NS007292); National Science Foundation; National Institutes of Health
Citations: not cited yet (Europe PMC); 66 references in the paper

Abstract

Recent advances in connectomics have been led by high-resolution reconstruction of large volumes of neural tissues using electron microscopy (EM), providing unprecedented insights into brain structure and function. Dendritic spines—dynamic protrusions on neuronal dendrites—play crucial roles in synaptic plasticity, influencing learning, memory, and various neurological disorders. However, current spine-analysis methods often rely on manual annotation of subcellular features, limiting their ability to handle the complexity of spines in dense dendritic networks. This paper introduces a novel automated computational framework that integrates discrete differential geometry, machine learning, and 3D image processing to analyze dendritic spines in these intricate environments. By generating distributions of spine morphology from high-resolution images including many thousands of spines, our approach captures subtle variations in spine shapes, offering a nuanced understanding of their roles in synaptic function. This framework is tested on multiple EM datasets with the aim of enhancing our understanding of synaptic plasticity and its alterations in disease states. The proposed method is poised to accelerate neuroscience research by providing a scalable, objective, and comprehensive solution for spine analysis, uncovering insights into the role of spine geometry for neural function.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above, with 7 matches between paragraphs and lines of code.

aka-gera/curvature-based-machine-learning-for-automated-segmentation-of-dendritic-spines

License: none: the authors keep all their rights
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 6dcc0e8463d84c4ec2e852e226a6e1635db5e0ed, 4 June 2026
Languages: Python (44), Jupyter (1), Shell (1)
Size: 146 files, 46 scripts
Software Heritage: not archived
Found in: “Data availability”
Holds: README, environment (requirements.txt, requirements_win.txt, dend_analysis/app/requirements.txt), 1 notebook
Not found: license file, CITATION.cff, tests, continuous integration, documentation
Tools: NumPy (34 files), scikit-learn (20 files), SciPy (13 files), TensorFlow (12 files), Keras (9 files), Plotly (9 files), pandas (5 files), NetworkX (2 files), scikit-image (2 files), Matplotlib (1 file), SHAP (1 file), XGBoost (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
47 files

Zenodo 19593999

License: CC-BY-4.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Size: 3 files
Software Heritage: not checked
Found in: “Data availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
  • 27 September 2026: the link answers (HTTP 200)

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 46 scripts, each with its path and the digest of its content;
  • 7 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data availability

To make these methods widely accessible, we have posted an open-source code repository on GitHub (GitHub:curvature-based-dendrite-segmentation (https://github.com/aka-gera/curvature-based-machine-learning-for-automated-segmentation-of-dendritic-spines)), with the trained model, training data, and validation data made available in a linked repository (Zenodo: https://doi.org/10.5281/zenodo.19593999).

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 2, 28 September 2026

  • Authors: added Thomas G Fai (0000-0003-0383-5217); removed Thomas G Fai

Version 1, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 5 MeSH terms, 4 funders, 36 references.

Cite

This paper

Geraldo, A. K. A., Chirillo, M. A., Harris, K. M., & Fai, T. G. (2026). Curvature-based machine-learning method for automated segmentation of dendritic spines. Biophysical journal, 125(14), 3604-3619. https://doi.org/10.1016/j.bpj.2026.06.005

BibTeX

@article{geraldo2026curvature,
author = {Geraldo, Abdel Kader A and Chirillo, Michael A and Harris, Kristen M and Fai, Thomas G},
title = {{Curvature-based machine-learning method for automated segmentation of dendritic spines}},
journal = {Biophysical journal},
year = {2026},
month = jun,
volume = {125},
number = {14},
pages = {3604--3619},
publisher = {Elsevier BV},
issn = {0006-3495},
doi = {10.1016/j.bpj.2026.06.005},
url = {https://doi.org/10.1016/j.bpj.2026.06.005},
pmid = {42249612},
pmcid = {PMC13335156}
}

RIS

TY - JOUR
AU - Geraldo, Abdel Kader A
AU - Chirillo, Michael A
AU - Harris, Kristen M
AU - Fai, Thomas G
TI - Curvature-based machine-learning method for automated segmentation of dendritic spines
T2 - Biophysical journal
J2 - Biophys J
PY - 2026
DA - 2026/06/05
VL - 125
IS - 14
SP - 3604
EP - 3619
SN - 0006-3495
PB - Elsevier BV
DO - 10.1016/j.bpj.2026.06.005
UR - https://doi.org/10.1016/j.bpj.2026.06.005
LA - en
ER -

CSL-JSON

{
"id": "10.1016/j.bpj.2026.06.005",
"type": "article-journal",
"title": "Curvature-based machine-learning method for automated segmentation of dendritic spines",
"container-title": "Biophysical journal",
"author": [
{
"family": "Geraldo",
"given": "Abdel Kader A"
},
{
"family": "Chirillo",
"given": "Michael A"
},
{
"family": "Harris",
"given": "Kristen M"
},
{
"family": "Fai",
"given": "Thomas G"
}
],
"container-title-short": "Biophys J",
"volume": "125",
"issue": "14",
"page": "3604-3619",
"DOI": "10.1016/j.bpj.2026.06.005",
"PMID": "42249612",
"PMCID": "PMC13335156",
"ISSN": "0006-3495",
"publisher": "Elsevier BV",
"URL": "https://doi.org/10.1016/j.bpj.2026.06.005",
"language": "en",
"issued": {
"date-parts": [
[
2026,
6,
5
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1371/journal.pcbi.1014571 [code]
SynAPSeg: A novel dataset and image analysis framework for deep learning-based synapse detection and quantification.
Journal: PLoS computational biology
In common: Keras, TensorFlow, NetworkX, 6 other tools, 5 references
[2] doi:10.1038/s42003-026-10957-8 [code]
Brain defence by the extracellular matrix protein Cochlin.
Journal: Communications biology
In common: SHAP, XGBoost, Keras, 9 other tools
[3] doi:10.1126/sciadv.aed3650 [code]
Truthful visualizations for mass spectrometry imaging enable high-spatial-resolution interactive &lt;i&gt;m/z&lt;/i&gt; mapping and exploration.
Journal: Science advances
In common: SHAP, XGBoost, Keras, 8 other tools
[4] doi:10.1038/s41598-026-48613-0 [code]
An snRNA-seq aging clock for the fruit fly head sheds light on sex-biased aging.
Journal: Scientific reports
In common: SHAP, XGBoost, Keras, 6 other tools, 2 references
[5] doi:10.1016/j.isci.2026.117010 [code]
Deep learning-assisted mapping of dendritic spines using sequential 2D two-photon calcium imaging.
Journal: iScience
In common: TensorFlow, scikit-image, scikit-learn, 4 other tools, histology / microscopy, 3 references
[6] doi:10.1016/j.isci.2026.116825 [code]
Social hierarchy shapes behavioral and transcriptional responses to chronic stress and ketamine in male mice.
Journal: iScience
In common: SHAP, XGBoost, NetworkX, 7 other tools
[7] doi:10.1016/j.celrep.2026.117793 [code]
Clustered inputs engage dendritic nonlinearities and calcium signaling to support efficient place-field formation in CA1 pyramidal neurons.
Journal: Cell reports
In common: SHAP, scikit-learn, pandas, 3 other tools, 4 references
[8] doi:10.3389/fnsys.2026.1822122 [code]
Convergence-divergence circuits for multimodal integration of innate and learned opponent valences.
Journal: Frontiers in systems neuroscience
In common: Keras, TensorFlow, NetworkX, 7 other tools
[9] doi:10.1016/j.xcrm.2026.102766 [code]
A longitudinal single-cell and spatial multiomic atlas of pediatric high-grade glioma.
Journal: Cell reports. Medicine
In common: Keras, TensorFlow, NetworkX, 7 other tools
[10] doi:10.3390/s26175327 [code]
Subject Identity Confounds qEEG Emotion Recognition on DEAP and DREAMER.
Journal: Sensors (Basel, Switzerland)
In common: SHAP, XGBoost, Keras, 6 other tools

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.