harpy.im.segment_points#
- harpy.im.segment_points(sdata, labels_name, points_name, name_x='x', name_y='y', name_gene='gene', model=<function baysor_callable>, output_labels_name='segmentation_mask', output_shapes_name='segmentation_mask_boundaries', labels_name_align=None, depth=100, chunks=None, boundary='reflect', trim=False, iou=True, iou_depth=2, iou_threshold=0.7, crd=None, to_coordinate_system='global', scale_factors=None, overwrite=False, **kwargs)#
Segment images using a
points_nameand a prior (labels_name) and add segmentation results (labels element and shapes element) to the SpatialData object.Currently only segmentation using a prior is supported (i.e.
labels_nameshould be provided). Thepoints_nameand thelabels_nameshould be registered (i.e. same coordinate space insdata).- Parameters:
sdata (
SpatialData) – The SpatialData object containing the image element to segment.labels_name (
str) – The labels element insdatato be used as a prior.points_name (
str) – The points element insdatato be used for segmentation.name_x (
str(default:'x')) – Column name for x-coordinates of the transcripts in the points element, by default “x”.name_y (
str(default:'y')) – Column name for y-coordinates of the transcripts in the points element, by default “y”.name_gene (
str(default:'gene')) – Column name in the points_name representing gene information.model (
Callable[...,ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]] (default:<function baysor_callable at 0x742f7c157ec0>)) – The segmentation model function used to process the images. Callable should take as input numpy arrays of dimension(z,y,x,c), a pandas dataframe with the transcripts, and parameters ‘name_x’, ‘name_y’ and ‘name_gene’ with the column names of the x and y location and the column name for the transcripts. It should return labels of dimension(z,y,x,c). Currently only 2D segmentation is supported(y,x). It can have an arbitrary number of other parameters.output_labels_name (
str|list[str] (default:'segmentation_mask')) – Name of the labels element in which segmentation results will be stored insdata. Can be a list of strings, ifmodelreturns multi channel mask. If provided as a list, its length should match thecdimension of the output ofmodel.output_shapes_name (
str|list[str] |None(default:'segmentation_mask_boundaries')) – Name of the shapes element where boundaries obtained output_labels_name will be stored. If set to None, shapes won’t be stored. Can be a list of strings, ifmodelreturns multi channel mask. If provided as a list, its length should match thecdimension of the output ofmodel.labels_name_align (
str|None(default:None)) – Name of the labels element inoutput_labels_nameto align to ifmodelretuns multi channel mask.depth (
tuple[int,int] |int(default:100)) – The depth inyandxdimension. The depth parameter is passed todask.array.map_overlap. If trim is set toFalse, it’s recommended to set the depth to a value greater than twice the estimated diameter of the cells/nulcei.chunks (
str|int|tuple[int,int] |None(default:None)) – Chunk sizes for processing. Can be a string, integer or tuple of integers. If chunks is a Tuple, they contain the chunk size that will be used inyandxdimension. Chunking inzorcdimension is not supported.boundary (
str(default:'reflect')) – Boundary parameter passed todask.array.map_overlap.trim (
bool(default:False)) – If set to True, overlapping regions will be processed using thesquidpyalgorithm. If set to False, theharpyalgorithm will be employed instead. For dense cell distributions, we recommend setting trim to False.iou (
bool(default:True)) – If set to True, will try to harmonize labels across chunks using a label adjacency graph with an iou threshold (seeharpy.image.segmentation.utils._link_labels). If set to False, conflicts will be resolved using an algorithm that only retains masks with the center in the chunk. Settingiouto False gives good results if there is reasonable agreement of the predicted labels accross adjacent chunks.iou_depth (
tuple[int,int] |int(default:2)) – iou depth used for harmonizing labels across chunks. Note that iflabels_name_alignis specified,iou_depthwill also be used for harmonizing labels between different chunks.iou_threshold (
float(default:0.7)) – iou threshold used for harmonizing labels across chunks. Note that iflabels_name_alignis specified,iou_thresholdwill also be used for harmonizing labels between different chunks.crd (
tuple[int,int,int,int] |None(default:None)) – The coordinates specifying the region of the image to be segmented. Defines the bounds(x_min, x_max, y_min, y_max).to_coordinate_system (
str(default:'global')) – The coordinate system to which thecrdis specified. Ignored ifcrdis None.scale_factors (
Sequence[dict[str,int] |int] |None(default:None)) – Scale factors to apply for multiscale.overwrite (
bool(default:False)) – IfTrue, overwrites the existing output elements if they exist. Otherwise, raises an error if they exist.**kwargs (
Any) – Additional keyword arguments passed to the providedmodel.
- Return type:
- Returns:
: Updated
sdataobject containing the segmentation results.- Raises:
TypeError – If the provided
modelis not callable.