Skip to content

Add RegionPropsNodes.add_node_attrs to recompute regionprops. - #321

Draft
yfukai wants to merge 1 commit into
royerlab:mainfrom
yfukai:regionprops_add_node_attrs
Draft

Add RegionPropsNodes.add_node_attrs to recompute regionprops.#321
yfukai wants to merge 1 commit into
royerlab:mainfrom
yfukai:regionprops_add_node_attrs

Conversation

@yfukai

@yfukai yfukai commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Human summary

This is intended to partly solve #265 by RegionPropsNode.add_node_attrs.

Copilot summary

This pull request extends the RegionPropsNodes operator to support (re-)computing region properties for existing nodes in a graph, adds comprehensive validation for extra properties, and introduces robust tests for the new functionality. The most important changes are:

New Feature: Recomputing Node Attributes

  • Added the add_node_attrs method to RegionPropsNodes, allowing users to (re-)compute region properties for existing nodes based on their stored masks, optionally using a provided intensity image. This enables adding new properties or updating existing ones without rebuilding the graph.
  • Introduced helper functions (_validate_properties, _add_missing_node_attr_keys, _region_property_attrs) to validate requested properties, register new attribute keys, and compute property values for a region. [1] [2] [3]

API Improvements

  • Added the mask_key parameter to the RegionPropsNodes constructor, allowing users to specify which node attribute contains the mask objects for property computation.
  • Improved error handling and validation for extra properties, including explicit rejection of "centroid" and "bbox" as extra properties and checks for missing/invalid mask attributes. [1] [2] [3]

Testing

  • Added a comprehensive suite of tests in test_regionprops.py to verify the correctness of attribute recomputation, validation logic, error handling, and support for custom callable properties and time-point selection.

These changes make the region property computation more flexible, robust, and user-friendly, especially for workflows that require updating or extending node attributes after initial graph creation.

…properties

Allows (re-)computing scikit-image region properties for nodes that already
exist in a graph, evaluating regionprops on each node's stored `Mask` instead
of on a labels image. Useful to compute properties that were not requested
when the nodes were created (e.g. intensity features of an additional channel)
or to refresh properties after masks were modified, without rebuilding the
graph.

Missing output attribute keys are registered in the graph with dtypes inferred
from the first computed values; existing keys are overwritten. The attribute
holding the masks is configurable through the new `mask_key` argument.

Property computation and attribute-key registration are factored out into
module-level `_region_property_attrs` / `_add_missing_node_attr_keys` helpers
shared with `add_nodes`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant