@@ -319,12 +319,12 @@ def downscaled_centroids(
319319 return new_array
320320
321321
322- def graph_connected_components (coords : dict , min_edge_distance : float , min_component_length : int ):
322+ def graph_connected_components (coords : dict , max_edge_distance : float , min_component_length : int ):
323323 """Create a list of IDs for each connected component of a graph.
324324
325325 Args:
326326 coords: Dictionary containing label IDs as keys and their position as value.
327- min_edge_distance : Maximal edge distance between graph nodes to create an edge between nodes.
327+ max_edge_distance : Maximal edge distance between graph nodes to create an edge between nodes.
328328 min_component_length: Minimal length of nodes of connected component. Filtered out if lower.
329329
330330 Returns:
@@ -335,12 +335,12 @@ def graph_connected_components(coords: dict, min_edge_distance: float, min_compo
335335 for num , pos in coords .items ():
336336 graph .add_node (num , pos = pos )
337337
338- # create edges between points whose distance is less than threshold min_edge_distance
338+ # create edges between points whose distance is less than threshold max_edge_distance
339339 for num_i , pos_i in coords .items ():
340340 for num_j , pos_j in coords .items ():
341341 if num_i < num_j :
342342 dist = math .dist (pos_i , pos_j )
343- if dist <= min_edge_distance :
343+ if dist <= max_edge_distance :
344344 graph .add_edge (num_i , num_j , weight = dist )
345345
346346 components = list (nx .connected_components (graph ))
@@ -360,7 +360,7 @@ def components_sgn(
360360 keyword : str = "distance_nn100" ,
361361 threshold_erode : Optional [float ] = None ,
362362 min_component_length : int = 50 ,
363- min_edge_distance : float = 30 ,
363+ max_edge_distance : float = 30 ,
364364 iterations_erode : Optional [int ] = None ,
365365 postprocess_threshold : Optional [float ] = None ,
366366 postprocess_components : Optional [List [int ]] = None ,
@@ -372,7 +372,7 @@ def components_sgn(
372372 keyword: Keyword of the dataframe column for erosion.
373373 threshold_erode: Threshold of column value after erosion step with spatial statistics.
374374 min_component_length: Minimal length for filtering out connected components.
375- min_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
375+ max_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
376376 iterations_erode: Number of iterations for erosion, normally determined automatically.
377377 postprocess_threshold: Post-process graph connected components by searching for points closer than threshold.
378378 postprocess_components: Post-process specific graph connected components ([0] for largest component only).
@@ -412,7 +412,7 @@ def components_sgn(
412412 for index , element in zip (labels_subset , centroids_subset ):
413413 coords [index ] = element
414414
415- components , _ = graph_connected_components (coords , min_edge_distance , min_component_length )
415+ components , _ = graph_connected_components (coords , max_edge_distance , min_component_length )
416416
417417 length_components = [len (c ) for c in components ]
418418 length_components , components = zip (* sorted (zip (length_components , components ), reverse = True ))
@@ -448,7 +448,7 @@ def label_components_sgn(
448448 min_size : int = 1000 ,
449449 threshold_erode : Optional [float ] = None ,
450450 min_component_length : int = 50 ,
451- min_edge_distance : float = 30 ,
451+ max_edge_distance : float = 30 ,
452452 iterations_erode : Optional [int ] = None ,
453453 postprocess_threshold : Optional [float ] = None ,
454454 postprocess_components : Optional [List [int ]] = None ,
@@ -460,7 +460,7 @@ def label_components_sgn(
460460 min_size: Minimal number of pixels for filtering small instances.
461461 threshold_erode: Threshold of column value after erosion step with spatial statistics.
462462 min_component_length: Minimal length for filtering out connected components.
463- min_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
463+ max_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
464464 iterations_erode: Number of iterations for erosion, normally determined automatically.
465465 postprocess_threshold: Post-process graph connected components by searching for points closer than threshold.
466466 postprocess_components: Post-process specific graph connected components ([0] for largest component only).
@@ -474,7 +474,7 @@ def label_components_sgn(
474474 table = table [table .n_pixels >= min_size ]
475475
476476 components = components_sgn (table , threshold_erode = threshold_erode , min_component_length = min_component_length ,
477- min_edge_distance = min_edge_distance , iterations_erode = iterations_erode ,
477+ max_edge_distance = max_edge_distance , iterations_erode = iterations_erode ,
478478 postprocess_threshold = postprocess_threshold ,
479479 postprocess_components = postprocess_components )
480480
@@ -496,7 +496,7 @@ def postprocess_sgn_seg(
496496 min_size : int = 1000 ,
497497 threshold_erode : Optional [float ] = None ,
498498 min_component_length : int = 50 ,
499- min_edge_distance : float = 30 ,
499+ max_edge_distance : float = 30 ,
500500 iterations_erode : Optional [int ] = None ,
501501) -> pd .DataFrame :
502502 """Postprocessing SGN segmentation of cochlea.
@@ -506,7 +506,7 @@ def postprocess_sgn_seg(
506506 min_size: Minimal number of pixels for filtering small instances.
507507 threshold_erode: Threshold of column value after erosion step with spatial statistics.
508508 min_component_length: Minimal length for filtering out connected components.
509- min_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
509+ max_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
510510 iterations_erode: Number of iterations for erosion, normally determined automatically.
511511
512512 Returns:
@@ -515,7 +515,7 @@ def postprocess_sgn_seg(
515515
516516 comp_labels = label_components_sgn (table , min_size = min_size , threshold_erode = threshold_erode ,
517517 min_component_length = min_component_length ,
518- min_edge_distance = min_edge_distance , iterations_erode = iterations_erode )
518+ max_edge_distance = max_edge_distance , iterations_erode = iterations_erode )
519519
520520 table .loc [:, "component_labels" ] = comp_labels
521521
@@ -525,14 +525,14 @@ def postprocess_sgn_seg(
525525def components_ihc (
526526 table : pd .DataFrame ,
527527 min_component_length : int = 50 ,
528- min_edge_distance : float = 30 ,
528+ max_edge_distance : float = 30 ,
529529):
530530 """Create connected components for IHC segmentation.
531531
532532 Args:
533533 table: Dataframe of segmentation table.
534534 min_component_length: Minimal length for filtering out connected components.
535- min_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
535+ max_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
536536
537537 Returns:
538538 Subgraph components as lists of label_ids of dataframe.
@@ -543,23 +543,23 @@ def components_ihc(
543543 for index , element in zip (labels , centroids ):
544544 coords [index ] = element
545545
546- components , _ = graph_connected_components (coords , min_edge_distance , min_component_length )
546+ components , _ = graph_connected_components (coords , max_edge_distance , min_component_length )
547547 return components
548548
549549
550550def label_components_ihc (
551551 table : pd .DataFrame ,
552552 min_size : int = 1000 ,
553553 min_component_length : int = 50 ,
554- min_edge_distance : float = 30 ,
554+ max_edge_distance : float = 30 ,
555555) -> List [int ]:
556556 """Label components using graph connected components.
557557
558558 Args:
559559 table: Dataframe of segmentation table.
560560 min_size: Minimal number of pixels for filtering small instances.
561561 min_component_length: Minimal length for filtering out connected components.
562- min_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
562+ max_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
563563
564564 Returns:
565565 List of component label for each point in dataframe. 0 - background, then in descending order of size
@@ -570,7 +570,7 @@ def label_components_ihc(
570570 table = table [table .n_pixels >= min_size ]
571571
572572 components = components_ihc (table , min_component_length = min_component_length ,
573- min_edge_distance = min_edge_distance )
573+ max_edge_distance = max_edge_distance )
574574
575575 # add size-filtered objects to have same initial length
576576 table = pd .concat ([table , entries_filtered ], ignore_index = True )
@@ -592,23 +592,23 @@ def postprocess_ihc_seg(
592592 table : pd .DataFrame ,
593593 min_size : int = 1000 ,
594594 min_component_length : int = 50 ,
595- min_edge_distance : float = 30 ,
595+ max_edge_distance : float = 30 ,
596596) -> pd .DataFrame :
597597 """Postprocessing IHC segmentation of cochlea.
598598
599599 Args:
600600 table: Dataframe of segmentation table.
601601 min_size: Minimal number of pixels for filtering small instances.
602602 min_component_length: Minimal length for filtering out connected components.
603- min_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
603+ max_edge_distance : Maximal distance in micrometer between points to create edges for connected components.
604604
605605 Returns:
606606 Dataframe with component labels.
607607 """
608608
609609 comp_labels = label_components_ihc (table , min_size = min_size ,
610610 min_component_length = min_component_length ,
611- min_edge_distance = min_edge_distance )
611+ max_edge_distance = max_edge_distance )
612612
613613 table .loc [:, "component_labels" ] = comp_labels
614614
0 commit comments