Skip to content

iscc.sample.tissue_image

tissue_image(coords, grid_side, px=14, darkness=0.85, sigma_frac=0.32, stain='he')

Rasterize cell positions into an H&E-like morphology background image.

Bins the (row, col) positions into a grid_side*px square raster, smooths the density, and maps it to colour (denser tissue → darker/more nuclear). This is the tissue image a spatial slide sits on — morphology only, carrying no per-cell data — suitable for adata.uns['spatial'][lib]['images']['hires'].

The density is normalised by a high percentile (not the single peak) and clipped, so one unusually dense patch does not wash out the contrast of the rest of the section — that peak-normalisation is what made an earlier version read as structureless.

Parameters:

Name Type Description Default
coords (array - like, shape(n_cells, 2))

Sub-deme cell positions as (row, col) (e.g. from :func:spatialize).

required
grid_side int or tuple of int

Capture-area extent in coordinate units: a scalar for a square area, or (rows, cols) to match a non-square spot array (e.g. the 78 x 64 Visium v1 slide).

required
px int

Pixels per coordinate unit; also the tissue_hires_scalef to record so that obsm['spatial'] maps onto the image.

14
darkness float

Maximum darkening of the densest tissue (0 = pale everywhere, 1 = full stain at peak).

0.85
sigma_frac float

Gaussian smoothing sigma as a fraction of px.

0.32
stain (he, grey)

"he" gives an eosin-pink stroma with hematoxylin-purple nuclei where dense (the canonical H&E look); "grey" gives the legacy greyscale (denser → darker).

"he"

Returns:

Name Type Description
image (ndarray, shape(rows * px, cols * px, 3), float32)

RGB morphology image in [0, 1].

scalef float

The tissue_hires_scalef (= px) to store alongside the image.