diff --git a/README.md b/README.md index 125aa79..03ed0fa 100644 --- a/README.md +++ b/README.md @@ -66,14 +66,14 @@ Inputs: - `min_area_ratio`: Removes tiny disconnected components before grouping and matching, with `0.01` step precision. Default is `0.01`; `0.0` disables filtering. Values are relative to the largest disconnected component in the same input group, so `0.02` removes components smaller than 2% of that largest component's foreground area. - `rows`: Number of equal-height bbox grid rows. Default is `4`. - `columns`: Number of equal-width bbox grid columns. Default is `1`. -- `auto_match_orientation`: Automatically swaps `rows` and `columns` for horizontal `mask1` product bboxes. Default is enabled. +- `auto_match_orientation`: Automatically makes the longer split direction follow the longer side of the `mask1` product bbox. Default is enabled. Outputs: - `mask1`: First sliced/grouped mask batch. - `mask2`: Second mask batch aligned to `mask1`. When only one input is connected, this is an empty placeholder batch. -The node splits disconnected painted islands internally, removes components below `min_area_ratio`, unions the remaining regions into one product mask, and slices that product bbox into a row-major grid: top to bottom, left to right. When `auto_match_orientation` is enabled, `rows=4, columns=1` stays 4x1 for vertical products and becomes 1x4 for horizontal products. In `mask` mode, empty `mask1` cells are skipped and `mask2` keeps the same remaining cell positions. In `bbox` mode, the full `rows × columns` rectangular grid is preserved. Use multiple rows and columns for two-dimensional local regions. +The node splits disconnected painted islands internally, removes components below `min_area_ratio`, unions the remaining regions into one product mask, and slices that product bbox into a row-major grid: top to bottom, left to right. When `auto_match_orientation` is enabled, the larger of `rows` and `columns` follows the longer side of the product bbox: `rows=4, columns=1` stays 4x1 for vertical products and becomes 1x4 for horizontal products, while `rows=1, columns=3` becomes 3x1 for vertical products and stays 1x3 for horizontal products. In `mask` mode, empty `mask1` cells are skipped and `mask2` keeps the same remaining cell positions. In `bbox` mode, the full `rows × columns` rectangular grid is preserved. Use multiple rows and columns for two-dimensional local regions. ### RefineNode Match Product Angle diff --git a/nodes.py b/nodes.py index 73611fa..e9c41c6 100644 --- a/nodes.py +++ b/nodes.py @@ -522,8 +522,13 @@ def slice_masks_by_product_bbox( if mask1_bbox is None: return ([Image.new("L", mask1_size, 0)], [Image.new("L", mask2_size, 0)]) - if auto_match_orientation and (mask1_bbox[2] - mask1_bbox[0]) > (mask1_bbox[3] - mask1_bbox[1]): - rows, columns = columns, rows + if auto_match_orientation and rows != columns: + long_count = max(rows, columns) + short_count = min(rows, columns) + if (mask1_bbox[2] - mask1_bbox[0]) > (mask1_bbox[3] - mask1_bbox[1]): + rows, columns = short_count, long_count + else: + rows, columns = long_count, short_count cells = normalized_grid_cells(rows, columns)