MCPcopy Create free account
hub / github.com/dcharatan/flowmap / resize

Function resize

flowmap/visualization/layout.py:217–237  ·  view source on GitHub ↗
(
    image: Float[Tensor, "channel height width"],
    shape: Optional[tuple[int, int]] = None,
    width: Optional[int] = None,
    height: Optional[int] = None,
)

Source from the content-addressed store, hash-verified

215
216
217def resize(
218 image: Float[Tensor, "channel height width"],
219 shape: Optional[tuple[int, int]] = None,
220 width: Optional[int] = None,
221 height: Optional[int] = None,
222) -> Float[Tensor, "channel new_height new_width"]:
223 assert (shape is not None) + (width is not None) + (height is not None) == 1
224 _, h, w = image.shape
225
226 if width is not None:
227 shape = (int(h * width / w), width)
228 elif height is not None:
229 shape = (height, int(w * height / h))
230
231 return F.interpolate(
232 image[None],
233 shape,
234 mode="bilinear",
235 align_corners=False,
236 antialias="bilinear",
237 )[0]
238
239
240def draw_label(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected