MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / ConvertBoxMode

Class ConvertBoxMode

monai/apps/detection/transforms/array.py:87–153  ·  view source on GitHub ↗

This transform converts the boxes in src_mode to the dst_mode. Args: src_mode: source box mode. If it is not given, this func will assume it is ``StandardMode()``. dst_mode: target box mode. If it is not given, this func will assume it is ``StandardMode()``. Note:

Source from the content-addressed store, hash-verified

85
86
87class ConvertBoxMode(Transform):
88 """
89 This transform converts the boxes in src_mode to the dst_mode.
90
91 Args:
92 src_mode: source box mode. If it is not given, this func will assume it is ``StandardMode()``.
93 dst_mode: target box mode. If it is not given, this func will assume it is ``StandardMode()``.
94
95 Note:
96 ``StandardMode`` = :class:`~monai.data.box_utils.CornerCornerModeTypeA`,
97 also represented as "xyxy" for 2D and "xyzxyz" for 3D.
98
99 src_mode and dst_mode can be:
100 #. str: choose from :class:`~monai.utils.enums.BoxModeName`, for example,
101 - "xyxy": boxes has format [xmin, ymin, xmax, ymax]
102 - "xyzxyz": boxes has format [xmin, ymin, zmin, xmax, ymax, zmax]
103 - "xxyy": boxes has format [xmin, xmax, ymin, ymax]
104 - "xxyyzz": boxes has format [xmin, xmax, ymin, ymax, zmin, zmax]
105 - "xyxyzz": boxes has format [xmin, ymin, xmax, ymax, zmin, zmax]
106 - "xywh": boxes has format [xmin, ymin, xsize, ysize]
107 - "xyzwhd": boxes has format [xmin, ymin, zmin, xsize, ysize, zsize]
108 - "ccwh": boxes has format [xcenter, ycenter, xsize, ysize]
109 - "cccwhd": boxes has format [xcenter, ycenter, zcenter, xsize, ysize, zsize]
110 #. BoxMode class: choose from the subclasses of :class:`~monai.data.box_utils.BoxMode`, for example,
111 - CornerCornerModeTypeA: equivalent to "xyxy" or "xyzxyz"
112 - CornerCornerModeTypeB: equivalent to "xxyy" or "xxyyzz"
113 - CornerCornerModeTypeC: equivalent to "xyxy" or "xyxyzz"
114 - CornerSizeMode: equivalent to "xywh" or "xyzwhd"
115 - CenterSizeMode: equivalent to "ccwh" or "cccwhd"
116 #. BoxMode object: choose from the subclasses of :class:`~monai.data.box_utils.BoxMode`, for example,
117 - CornerCornerModeTypeA(): equivalent to "xyxy" or "xyzxyz"
118 - CornerCornerModeTypeB(): equivalent to "xxyy" or "xxyyzz"
119 - CornerCornerModeTypeC(): equivalent to "xyxy" or "xyxyzz"
120 - CornerSizeMode(): equivalent to "xywh" or "xyzwhd"
121 - CenterSizeMode(): equivalent to "ccwh" or "cccwhd"
122 #. None: will assume mode is ``StandardMode()``
123
124 Example:
125 .. code-block:: python
126
127 boxes = torch.ones(10,4)
128 # convert boxes with format [xmin, ymin, xmax, ymax] to [xcenter, ycenter, xsize, ysize].
129 box_converter = ConvertBoxMode(src_mode="xyxy", dst_mode="ccwh")
130 box_converter(boxes)
131 """
132
133 backend = [TransformBackends.TORCH, TransformBackends.NUMPY]
134
135 def __init__(
136 self,
137 src_mode: str | BoxMode | type[BoxMode] | None = None,
138 dst_mode: str | BoxMode | type[BoxMode] | None = None,
139 ) -> None:
140 self.src_mode = src_mode
141 self.dst_mode = dst_mode
142
143 def __call__(self, boxes: NdarrayOrTensor) -> NdarrayOrTensor:
144 """

Callers 3

__init__Method · 0.90
inverseMethod · 0.90
inverseMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…