dict_to_json_store

dict_to_json_store(processed_predictions, output_path, output_type, class_dict=None, origin=(0, 0), scale_factor=(1, 1), num_workers=2, *, verbose=True)[source]

Write polygonal multitask predictions into an QuPath JSON or AnnotationStore.

Converts a task dictionary (with per-object fields) into Annotation records, applying coordinate scaling and translation to move predictions into the slide’s baseline coordinate space. Each geometry is created from the per-object “contours” entry, validated, and shifted by origin. All remaining keys in processed_predictions are attached as annotation properties; the “type” key can be mapped via class_dict.

Expected processed_predictions structure:
  • “contours”: list-like of polygon coordinates per object, where each item is shaped like [[x0, y0], [x1, y1], …, [xN, yN]]. These are interpreted according to “geom_type” (default “Polygon”).

  • Optional “geom_type”: str (e.g., “Polygon”, “MultiPolygon”). Defaults to “Polygon”.

  • Additional per-object fields (e.g., “type”, “probability”, scores, attributes) with list-like values aligned to contours length.

Parameters:
  • processed_predictions (dict) – Dictionary containing per-object fields. Must include “contours”; may include “geom_type” and any number of additional fields to be written as properties.

  • output_path (Path) – Path to save the output.

  • output_type (str) – Desired output format: “qupath” or “annotationstore”.

  • class_dict (dict | None) – Optional mapping for the “type” field. When provided and when “type” is present in processed_predictions, each “type” value is replaced by class_dict[type_id] in the saved annotation properties.

  • origin (tuple[float, float]) – (x0, y0) offset to add to the final geometry coordinates (in pixels) after scaling. Typically corresponds to the tile/patch origin in WSI space.

  • scale_factor (tuple[float, float]) – (sx, sy) factors applied to coordinates before translation, used to convert from model space to baseline slide resolution (e.g., model_mpp / slide_mpp).

  • num_workers (int) – Number of parallel worker threads to use. If set to 0 or None, defaults to the number of CPU cores.

  • verbose (bool) – Whether to display logs and progress bar.

Returns:

The input store after appending all converted annotations.

Return type:

AnnotationStore

Notes

  • Geometries are constructed from processed_predictions[“contours”] using geom_type (default “Polygon”), scaled by scale_factor, and translated by origin. Invalid geometries are auto-corrected using make_valid_poly.

  • Per-object properties are created by taking the i-th element from each remaining key in processed_predictions. Scalars are coerced to arrays first, then converted with .tolist() to ensure JSON-serializable values.

  • If class_dict is provided and a “type” key exists, “type” values are mapped prior to saving.

  • All annotations are appended in a single batch via store.append_many(…).