sddb.loader.Rasterize#
- class sddb.loader.Rasterize(mpp: float | None, *, allow_upsample: bool = False, tile: int = 4096, value_range: Sequence[float] | None = None)#
Resample the image and the cells onto the written grid.
The written grid is axis-aligned in the coordinate system the image shares with the cells and covers the image's footprint there, so any rotation or affine of the image is baked in. Its pixel is
mppmicrons (the"target"grid) or, withoutmppor with an unknownmpp_native, the size of an image pixel (the"native"grid,native_to_written = 1).The image is resampled (order 1) from the coarsest multiscale level whose mpp is still at most
mpp, and converted to the role's dtype by a rule recorded initem.dtype_rule(seevalue_range). An H&E source is already 3-channel uint8 (LoaderItem.from_sdata()drops a constant alpha and refuses anything else), so only an IF source is converted to uint16. Outside the image's footprint the written image is glass (255) for H&E and 0 for IF. Existing labels are resampled with order 0; otherwise the shapes the table annotates are rasterised once, filled, with each row'sobs["label_id"], one tile oftile x tilepixels at a time.- Parameters:
- mpp
Microns per pixel of the target grid, or
Nonefor the native grid.- allow_upsample
Allow a target finer than the native grid (
mpp_native / mpp > 1). Without it any such factor raises.- tile
Chunk side of the written image and labels, and of the rasterisation tiles.
- value_range
(lo, hi)of the source pixels, mapped linearly onto the role's dtype (loto 0,hito its max). Without it, a source already in the role's dtype passes through, and any other source must fit its dtype's natural range, judged from the min and max of the coarsest pyramid level: a float in[0, 1]is scaled to the role's max, an integer whose values fit the role's dtype keeps them. Anything else raises and asks forvalue_range.
Attributes table#
Methods table#
build(sdata)Return the item on the written grid, with
labels["cells"].from_record(rec)Rebuild the step from
to_record()'s output.An item fresh from
LoaderItem.from_sdata().The step as an
AdapterRecordthatfrom_record()rebuilds.validate(sdata)Refuse an item that was already rasterised, and upsampling unless it is allowed.
validate_meta(meta)No catalog metadata decides these steps; the checks run on the item in
validate().Attributes#
Methods#
- build(sdata: LoaderItem) LoaderItem#
Return the item on the written grid, with
labels["cells"].
- classmethod from_record(rec: AdapterRecord) Self#
Rebuild the step from
to_record()'s output.- Raises:
ValueError -- If the record is of another adapter or another version.
- requirements() dict[str, Any]#
An item fresh from
LoaderItem.from_sdata().
- to_record() AdapterRecord#
The step as an
AdapterRecordthatfrom_record()rebuilds.
- validate(sdata: LoaderItem) list[str]#
Refuse an item that was already rasterised, and upsampling unless it is allowed.
- validate_meta(meta: ObjectMeta) list[str]#
No catalog metadata decides these steps; the checks run on the item in
validate().