Nodes/ComfyUI-MultiMaskOps/Mask Sort By Position
ComfyUI Node

Mask Sort By Position

A ComfyUI node in MultiMaskOps with 8 inputs and 2 outputs.

By INuBq8·Created about a month ago·Updated about a month ago· 0
Mask Sort By Position
  • masks
  • masks
  • debug_image
reference_point
sort_left_to_righttrue
sort_top_to_bottomtrue
primary_axis_horizontaltrue
flatten_before_sortfalse
drop_below_thresholdfalse
threshold0.50
CategoryMultiMaskOps

Inputs (8)

NameTypeDefaultDescription
masksMASKA list of masks to sort by spatial position.
reference_pointCOMBOWhich point of each mask to sort by. 'centroid' = value-weighted center of the mask. 'extreme_point' = the outermost pixel along the primary sort direction (e.g. leftmost pixel when sorting left-to-right).
sort_left_to_rightBOOLEANtrueHorizontal direction. True = left to right, False = right to left.
sort_top_to_bottomBOOLEANtrueVertical direction. True = top to bottom, False = bottom to top.
primary_axis_horizontalBOOLEANtrueWhich axis sorts first. True = sort horizontally first, then vertically to break ties. False = vertical first, then horizontal.
flatten_before_sortBOOLEANfalseIf enabled, each mask is binarized at 'threshold' before its sort point is computed. Only affects sorting; output masks are unchanged.
drop_below_thresholdBOOLEANfalseIf enabled (and not flattening), pixels below 'threshold' are ignored when computing the sort point (a thresholded ReLU). Only affects sorting; output masks are unchanged.
thresholdFLOAT0.500–1Cutoff used by flatten_before_sort and drop_below_threshold to decide which pixels count when computing each mask's sort point.

Outputs (2)

NameTypeDescription
masksMASKThe input masks reordered by spatial position.
debug_imageIMAGEA white image with a black dot marking each mask's sort reference point, in sorted order. For debugging.