Utilities#
- kornia.image.make_grid(tensor, n_row=None, padding=2)[source]#
Convert a batched tensor to one image with padding in between.
- Convention:
n_rowis the number of images in each row, that is the number of columns, as torchvision’snrow; it defaults to \(\lceil \sqrt{B} \rceil\). The images fill each row in batch order, zero images complete the last row, andn_row > Bstill givesn_rowcolumns.paddingzeros go between the images only, with no outer border, and the channels are kept:Rrows ofn_rowimages give \((C, R (H + p) - p, n_{row} (W + p) - p)\) for \(p\) =padding.The grid is a new tensor in the input’s dtype and on its device; \(B = 0\) gives a zero-height grid.
Files and arrays compares it with torchvision’s
make_grid.
- Parameters:
tensor (
Tensor) – A batched tensor of shape (B, C, H, W).n_row (
Optional[int], optional) – Number of images displayed in each row of the grid. IfNone, use the square root of the batch size rounded up. Images are placed in batch order, filling each row before the next. Default:Nonepadding (
int, optional) – The amount of padding to add between images; must be non-negative. Default:2
- Returns:
The combined image grid.
- Return type:
- Raises:
TypeError – if
tensoris not atorch.Tensor.ValueError – if
tensoris not four dimensional,n_rowis not positive orpaddingis negative.
- kornia.image.perform_keep_shape_image(f)[source]#
Apply
fto an image of arbitrary leading dimensions(*, C, H, W).- Convention:
falways receives a(B, C, H, W)tensor: an(H, W)input becomes(1, 1, H, W), a(C, H, W)input(1, C, H, W), and the leading dimensions of a longer input are flattened intoB. The output gets the input’s leading dimensions back aroundf’s ownC,HandW, except that an(H, W)input getsf’s first channel only;fmust keep the batch size.An empty input raises
ValueErrorbeforefis called.
- kornia.image.perform_keep_shape_video(f)[source]#
Apply
fto an image of arbitrary leading dimensions(*, C, D, H, W).- Convention:
See the Convention block of
perform_keep_shape_image(), withfreceiving(B, C, D, H, W): a(D, H, W)input becomes(1, 1, D, H, W)and a(C, D, H, W)input(1, C, D, H, W).