cutcutcodec.core.filter.video.patch.patch
- cutcutcodec.core.filter.video.patch.patch(image: FrameVideo | Tensor | ndarray, anchor: tuple[Integral, Integral] | list[Integral], shape: tuple[Integral, Integral] | list[Integral], copy: bool = True) FrameVideo | Tensor | ndarray[source]
Extract part of the image seen through a window.
If the window protrudes from the image, it is padded with transparent layer.
Parameters
- imagecutcutcodec.core.classes.image_video.FrameVideo or torch.Tensor or numpy.ndarray
The image to be patch. If a numpy array is provide, the format has to match with the video image specifications.
- anchorint and int
The position of the top left corner of the window. The convention adopted is the numpy convention (height, width).
- shapeint and int
The pixel dimensions of the returned image. The convention adopted is the numpy convention (height, width).
- copyboolean, default=True
If True, ensure that the returned tensor doesn’t share the data of the input tensor.
Returns
- patched_image
The patched view image homogeneous with the input.
Examples
>>> import torch >>> from cutcutcodec.core.classes.frame_video import FrameVideo >>> from cutcutcodec.core.filter.video.patch import patch >>> ref = FrameVideo(0, torch.full((4, 8, 1), 128, dtype=torch.uint8)) >>> patch(ref, (-2, -2), (7, 11))[..., 1] # alpha layer tensor([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0], [ 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0], [ 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0], [ 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=torch.uint8) >>> patch(ref, (1, 1), (2, 6)).convert(1)[..., 0] # as gray tensor([[128, 128, 128, 128, 128, 128], [128, 128, 128, 128, 128, 128]], dtype=torch.uint8) >>> patch(ref, (-1, -2), (4, 8)).convert(1)[..., 0] # as gray tensor([[ 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 128, 128, 128, 128, 128, 128], [ 0, 0, 128, 128, 128, 128, 128, 128], [ 0, 0, 128, 128, 128, 128, 128, 128]], dtype=torch.uint8) >>> patch(ref, (1, 2), (4, 8)).convert(1)[..., 0] # as gray tensor([[128, 128, 128, 128, 128, 128, 0, 0], [128, 128, 128, 128, 128, 128, 0, 0], [128, 128, 128, 128, 128, 128, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0]], dtype=torch.uint8) >>> patch(ref, (-2, -2), (4, 2)).convert(1)[..., 0] # as gray tensor([[0, 0], [0, 0], [0, 0], [0, 0]], dtype=torch.uint8) >>> patch(ref, (-2, 6), (2, 4)).convert(1)[..., 0] # as gray tensor([[0, 0, 0, 0], [0, 0, 0, 0]], dtype=torch.uint8) >>>