MCPcopy
hub / github.com/Janspiry/Palette-Image-to-Image-Diffusion-Models / bbox2mask

Function bbox2mask

data/util/mask.py:100–123  ·  view source on GitHub ↗

Generate mask in ndarray from bbox. The returned mask has the shape of (h, w, 1). '1' indicates the hole and '0' indicates the valid regions. We prefer to use `uint8` as the data type of masks, which may be different from other codes in the community. Args: im

(img_shape, bbox, dtype='uint8')

Source from the content-addressed store, hash-verified

98
99
100def bbox2mask(img_shape, bbox, dtype='uint8'):
101 """Generate mask in ndarray from bbox.
102
103 The returned mask has the shape of (h, w, 1). '1' indicates the
104 hole and '0' indicates the valid regions.
105
106 We prefer to use `uint8` as the data type of masks, which may be different
107 from other codes in the community.
108
109 Args:
110 img_shape (tuple[int]): The size of the image.
111 bbox (tuple[int]): Configuration tuple, (top, left, height, width)
112 dtype (str): Indicate the data type of returned masks. Default: 'uint8'
113
114 Return:
115 numpy.ndarray: Mask in the shape of (h, w, 1).
116 """
117
118 height, width = img_shape[:2]
119
120 mask = np.zeros((height, width, 1), dtype=dtype)
121 mask[bbox[0]:bbox[0] + bbox[2], bbox[1]:bbox[1] + bbox[3], :] = 1
122
123 return mask
124
125
126def brush_stroke_mask(img_shape,

Callers 2

get_maskMethod · 0.85
get_maskMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected