make_tiles#
- squidpy.experimental.im.make_tiles(sdata, *, image_key, image_mask_key=None, tissue_mask_key=None, tile_size=(224, 224), center_grid_on_tissue=False, scale='auto', min_tissue_fraction=1.0, new_shapes_key=None, preview=True)[source]#
Create a regular grid of tiles over an image, classify them by tissue coverage, and optionally render a preview.
Tiles are generated on the highest-resolution image scale and classified into three categories based on the supplied (or automatically derived) tissue mask:
"background": no tissue pixels in the tile."partial_tissue": some tissue but belowmin_tissue_fraction."tissue": at leastmin_tissue_fractionof the tile is tissue.
The resulting grid is stored in
sdata.shapes[new_shapes_key](defaultf"{image_key}_tiles") with one row per tile and columns such aspixel_y0,pixel_x0,pixel_y1,pixel_x1, andtile_classification.- Parameters:
- sdata
SpatialData SpatialData object containing the image and (optionally) label masks.
- image_key
str Key of the image in
sdata.imagesto tile.- image_mask_key
str|None(default:None) Optional key of a segmentation or tissue mask in
sdata.labelsused purely to position the grid. Ifcenter_grid_on_tissueisTrueand this is not provided, the function will fall back totissue_mask_keyorf"{image_key}_tissue"if present, or automatically rundetect_tissue()to create one.- tissue_mask_key
str|None(default:None) Key of the tissue mask in
sdata.labelsused for classification. IfNone, the function usesf"{image_key}_tissue"and will automatically rundetect_tissue()to create this mask if it does not exist.- tile_size
tuple[int,int] (default:(224, 224)) Size of tiles as
(height, width)in pixels on the largest image scale.- center_grid_on_tissue
bool(default:False) If
True, center the tile grid on the centroid of the mask given byimage_mask_key/tissue_mask_key/f"{image_key}_tissue"(created on the fly if needed). IfFalse, the grid starts at the top-left corner of the image.- scale
str(default:'auto') Label scale to use when reading the mask for centering and classification. If
"auto", the function chooses the label scale whose shape is closest to the full-resolution image dimensions.- min_tissue_fraction
float(default:1.0) Minimum fraction of a tile that must be tissue for it to be considered suitable for inference. Tiles below this threshold are classified as
"background"(0%) or"partial_tissue"(>0%).- new_shapes_key
str|None(default:None) Key under which to store the tile grid in
sdata.shapes. Defaults tof"{image_key}_tiles".- preview
bool(default:True) If
True, render a preview usingsdata.pl.render_images(image_key)overlaid with the tiles colored bytile_classification.
- sdata
- Returns:
None– None All results are written in-place tosdata.shapes.
See also
detect_tissueHelper used to automatically derive a tissue mask when none is provided.
make_tiles_from_spotsCreate tiles centered on Visium spots instead of a regular grid.