cutcutcodec.core.filter.mix.video_cast

Basic casts between different video profiles.

Functions

to_gray(frame)

Convert any video frame into a 1 gray channel frame.

to_gray_alpha(frame)

Convert any video frame into a 2 channels (gray, alpha) frame.

to_rgb(frame)

Convert any video frame into a 3 channels (blue, green, red) frame.

to_rgb_alpha(frame)

Convert any video frame into a 4 channels (blue, green, red, alpha) frame.

Details

cutcutcodec.core.filter.mix.video_cast.to_gray(frame: Tensor) Tensor[source]

Convert any video frame into a 1 gray channel frame.

Parameters

frametorch.Tensor

The input frame of shape (height, width, channels).

Returns

frame

The output 1 gray channel frame. Type has to be floating point or uint8. This will be a new view object if possible; otherwise, it will be a copy.

Examples

>>> import torch
>>> from cutcutcodec.core.filter.mix.video_cast import to_gray
>>> _ = torch.manual_seed(0)
>>> for dtype in (torch.uint8, torch.float32):
...     for channels in (1, 2, 3, 4):
...         if dtype == torch.uint8:
...             frame = torch.randint(0, 256, (480, 720, channels), dtype=torch.uint8)
...         else:
...             frame = torch.rand((480, 720, channels), dtype=dtype)
...         assert to_gray(frame).shape == (480, 720, 1)
...         assert to_gray(frame).dtype == dtype
...
>>>
cutcutcodec.core.filter.mix.video_cast.to_gray_alpha(frame: Tensor) Tensor[source]

Convert any video frame into a 2 channels (gray, alpha) frame.

Parameters

frametorch.Tensor

The input frame of shape (height, width, channels).

Returns

frame

The output 2 gray alpha channels frame. Type has to be floating point or uint8. This will be a new view object if possible; otherwise, it will be a copy.

Examples

>>> import torch
>>> from cutcutcodec.core.filter.mix.video_cast import to_gray_alpha
>>> _ = torch.manual_seed(0)
>>> for dtype in (torch.uint8, torch.float32):
...     for channels in (1, 2, 3, 4):
...         if dtype == torch.uint8:
...             frame = torch.randint(0, 256, (480, 720, channels), dtype=torch.uint8)
...         else:
...             frame = torch.rand((480, 720, channels), dtype=dtype)
...         assert to_gray_alpha(frame).shape == (480, 720, 2)
...         assert to_gray_alpha(frame).dtype == dtype
...
>>>
cutcutcodec.core.filter.mix.video_cast.to_rgb(frame: Tensor) Tensor[source]

Convert any video frame into a 3 channels (blue, green, red) frame.

Parameters

frametorch.Tensor

The input frame of shape (height, width, channels).

Returns

frame

The output 3 blue, green, red channels frame. Type has to be floating point or uint8. This will be a new view object if possible; otherwise, it will be a copy.

Examples

>>> import torch
>>> from cutcutcodec.core.filter.mix.video_cast import to_rgb
>>> _ = torch.manual_seed(0)
>>> for dtype in (torch.uint8, torch.float32):
...     for channels in (1, 2, 3, 4):
...         if dtype == torch.uint8:
...             frame = torch.randint(0, 256, (480, 720, channels), dtype=torch.uint8)
...         else:
...             frame = torch.rand((480, 720, channels), dtype=dtype)
...         assert to_rgb(frame).shape == (480, 720, 3)
...         assert to_rgb(frame).dtype == dtype
...
>>>
cutcutcodec.core.filter.mix.video_cast.to_rgb_alpha(frame: Tensor) Tensor[source]

Convert any video frame into a 4 channels (blue, green, red, alpha) frame.

Parameters

frametorch.Tensor

The input frame of shape (height, width, channels).

Returns

frame

The output 4 blue, green, red alpha channels frame. Type has to be floating point or uint8. This will be a new view object if possible; otherwise, it will be a copy.

Examples

>>> import torch
>>> from cutcutcodec.core.filter.mix.video_cast import to_rgb_alpha
>>> _ = torch.manual_seed(0)
>>> for dtype in (torch.uint8, torch.float32):
...     for channels in (1, 2, 3, 4):
...         if dtype == torch.uint8:
...             frame = torch.randint(0, 256, (480, 720, channels), dtype=torch.uint8)
...         else:
...             frame = torch.rand((480, 720, channels), dtype=dtype)
...         assert to_rgb_alpha(frame).shape == (480, 720, 4)
...         assert to_rgb_alpha(frame).dtype == dtype
...
>>>