TV API

class cvcuda.tv.Compose(transforms)

Run a TorchVision v2 transform pipeline on CV-CUDA. Requires PyTorch and TorchVision; the functional API below does not require either dependency for cvcuda.Tensor inputs.

Parameters:

transforms – A non-empty list or tuple of TorchVision v2 transforms.

Raises:

TypeError – If a transform is unsupported, including at any nesting depth.

Calling the pipeline accepts a cvcuda.Tensor in HWC, NHWC, CHW or NCHW layout, or a CUDA torch.Tensor/tv_tensors.Image with 3 or 4 dimensions and non-zero strides. It returns the same kind and preserves the CV-CUDA layout, with one output per crop for FiveCrop or TenCrop. Operations use the current Torch stream of the input’s device.

See TorchVision pipelines for supported transforms, usage and performance.

cvcuda.tv.adjust_brightness(inpt: Tensor, brightness_factor: float, *, stream: Stream | None = None) → Tensor[source]

Scale image brightness and clamp to the image value range.

Computes clamp(brightness_factor * in, 0, bound), where bound is 1.0 for floating-point images and the dtype maximum for integer images.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • brightness_factor (float) – Non-negative brightness multiplier.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

Raises:

ValueError – If brightness_factor is negative.

cvcuda.tv.adjust_contrast(inpt: Tensor, contrast_factor: float, *, stream: Stream | None = None) → Tensor[source]

Blend each image toward its grayscale mean.

out = clamp(contrast_factor * in + (1 - contrast_factor) * mean, 0, bound), where mean is the per-image grayscale mean (BT.601 luma 0.2989 R + 0.587 G + 0.114 B).

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s), 1 or 3 channels.

  • contrast_factor (float) – Non-negative contrast multiplier.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

cvcuda.tv.adjust_gamma(inpt: Tensor, gamma: float, gain: float = 1.0, *, stream: Stream | None = None) → Tensor[source]

Gamma correction: out = gain * in**gamma.

Values are interpreted in the normalized image range and clamped to the output dtype range.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s), interleaved ((N)HWC) or planar ((N)CHW).

  • gamma (float) – Non-negative gamma exponent.

  • gain (float, optional) – Output gain. Defaults to 1.0.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

Raises:

ValueError – If gamma is negative.

cvcuda.tv.adjust_hue(inpt: Tensor, hue_factor: float, *, stream: Stream | None = None) → Tensor[source]

Rotate image hue by hue_factor in HSV space.

The hue channel is shifted modulo 1. Single-channel images are unchanged.

Parameters:
  • inpt (cvcuda.Tensor) – Input RGB or single-channel image(s).

  • hue_factor (float) – Rotation in [-0.5, 0.5]; 0 is unchanged and either endpoint rotates hue by 180 degrees.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

cvcuda.tv.adjust_saturation(inpt: Tensor, saturation_factor: float, *, stream: Stream | None = None) → Tensor[source]

Blend an RGB image toward its grayscale by saturation_factor.

A factor of 0 produces grayscale, 1 leaves the image unchanged, and values above 1 increase saturation. Single-channel images are unchanged.

Parameters:
  • inpt (cvcuda.Tensor) – Input RGB or single-channel image(s).

  • saturation_factor (float) – Non-negative saturation multiplier.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

cvcuda.tv.adjust_sharpness(inpt: Tensor, sharpness_factor: float, *, stream: Stream | None = None) → Tensor[source]

Adjust image sharpness.

Each image is blended with a 3x3-smoothed version of its interior. A factor of 0 produces the smoothed image, 1 leaves it unchanged, and values above 1 sharpen it. The one-pixel border and images smaller than 3 pixels in either spatial dimension are unchanged.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s) with 1 or 3 channels.

  • sharpness_factor (float) – Non-negative blend weight applied to the input.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

Raises:

ValueError – If sharpness_factor is negative.

cvcuda.tv.affine(inpt: Tensor, angle: float, translate: Sequence[int | float], scale: float, shear: int | float | Sequence[int | float], interpolation: InterpolationMode | Enum | str | int = InterpolationMode.NEAREST, fill: int | float | Sequence[float] | None = None, center: Sequence[int | float] | None = None, *, stream: Stream | None = None) → Tensor[source]

Apply an affine transformation to image(s).

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • angle (float) – Rotation in degrees.

  • translate (list[int]) – Horizontal / vertical translation in pixels.

  • scale (float) – Isotropic scale factor.

  • shear (float | list[float]) – Shear angle(s) in degrees (x or [x, y]).

  • interpolation (InterpolationMode | str | int, optional) – Interpolation mode. Supports nearest and bilinear. Defaults to nearest.

  • fill (int | float | list[float], optional) – Constant fill for exposed pixels.

  • center (list[float], optional) – Center of the transform, origin top-left; defaults to the image center.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Transformed image(s).

Return type:

cvcuda.Tensor

Raises:

ValueError – If interpolation is unsupported or scale is not positive.

cvcuda.tv.autocontrast(inpt: Tensor, *, stream: Stream | None = None) → Tensor[source]

Stretch each image to the full value range.

Each channel is remapped independently so its minimum becomes zero and its maximum becomes the dtype bound. Flat channels are unchanged. Integer results are floor((x - min) * bound / (max - min)), matching Pillow; torchvision’s tensor kernel can be one lower where that quotient is a whole number.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s) with 1 or 3 channels.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

Raises:

TypeError – If inpt does not have 1 or 3 channels.

cvcuda.tv.center_crop(inpt: Tensor, output_size: int | Sequence[int], *, stream: Stream | None = None) → Tensor[source]

Crop the center region from image(s).

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • output_size (int | list[int]) – Center-crop [height, width] (a scalar crops a square).

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

The center crop.

Return type:

cvcuda.Tensor

cvcuda.tv.crop(inpt: Tensor, top: int, left: int, height: int, width: int, *, stream: Stream | None = None) → Tensor[source]

Crop a rectangular region from image(s).

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • top (int) – Top-left corner of the crop (row, column).

  • left (int) – Top-left corner of the crop (row, column).

  • height (int) – Crop extent.

  • width (int) – Crop extent.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

The cropped region.

Return type:

cvcuda.Tensor

Note

A rectangle extending past the input is cropped to the overlap and then zero-padded back out to the requested extent, matching torchvision.

cvcuda.tv.elastic(inpt: Tensor, displacement: Tensor, interpolation: InterpolationMode | Enum | str | int = InterpolationMode.BILINEAR, fill: int | float | Sequence[float] | None = None, *, stream: Stream | None = None) → Tensor[source]

Apply an elastic deformation to image(s).

As in torchvision, displacement is relative: it is added to the identity sampling grid, in normalized [-1, 1] coordinates with align_corners=False. One displacement applies to every image of a batch.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • displacement (cvcuda.Tensor) – Relative normalized displacement of shape (1, H, W, 2), last axis (dx, dy), in NHWC layout.

  • interpolation (InterpolationMode | str | int, optional) – Interpolation mode. Defaults to bilinear.

  • fill (int | float | list[float], optional) – Constant fill for exposed pixels.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Deformed image(s).

Return type:

cvcuda.Tensor

Raises:

ValueError – If displacement is not of shape (1, H, W, 2).

cvcuda.tv.equalize(inpt: Tensor, *, stream: Stream | None = None) → Tensor[source]

Histogram-equalize image(s) with Pillow’s lookup table.

The integer lookup table matches Pillow’s, which torchvision also uses. Normalized floating-point images are binned to 8 bits, equalized and scaled back. Float16 bins through float32, deliberately avoiding torchvision’s half-precision multiplier rounding to 256 and wrapping 1.0 to bin zero.

Parameters:
  • inpt (cvcuda.Tensor) – Input uint8 or floating-point image(s).

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

cvcuda.tv.erase(inpt: Tensor, i: int, j: int, h: int, w: int, v: Tensor, inplace: bool = False, *, stream: Stream | None = None) → Tensor[source]

Erase (fill) a rectangular region of image(s).

The region follows Python slice semantics. v is broadcast over the region and must be a CUDA-resident cvcuda.Tensor on the same device as inpt. The image and value dtypes must match, or v may be float32. A torch.Tensor v is moved to the image’s device and cast to its dtype, as torchvision’s assignment does.

Parameters:
  • inpt (cvcuda.Tensor) – Input integer or floating-point image tensor in HWC, NHWC, CHW, or NCHW layout.

  • i (int) – Top coordinate of the region.

  • j (int) – Left coordinate of the region.

  • h (int) – Region height.

  • w (int) – Region width.

  • v (cvcuda.Tensor) – Scalar or broadcastable fill value.

  • inplace (bool, optional) – Write the result into inpt. Defaults to False.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

The filled image tensor; inpt itself when inplace

is True.

Return type:

cvcuda.Tensor

cvcuda.tv.five_crop(inpt: Tensor, size: int | Sequence[int], *, stream: Stream | None = None) → tuple[Tensor, Tensor, Tensor, Tensor, Tensor][source]

Crop image(s) into the four corners and the center (five crops).

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • size (int | list[int]) – Crop [height, width] (a scalar crops a square).

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Top-left, top-right, bottom-left,

bottom-right, and center crops, in that order.

Return type:

tuple[cvcuda.Tensor, …]

cvcuda.tv.gaussian_blur(inpt: Tensor, kernel_size: int | Sequence[int], sigma: int | float | Sequence[float] | None = None, *, stream: Stream | None = None) → Tensor[source]

Blur image(s) with a Gaussian kernel.

The image boundary is reflected before filtering. When sigma is omitted, each value is derived from its kernel size as kernel_size * 0.15 + 0.35.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • kernel_size (int | list[int]) – Gaussian kernel size [kw, kh] (an int is broadcast to both axes); must be odd and positive.

  • sigma (float | list[float], optional) – Gaussian standard deviation(s); when omitted it is derived from kernel_size.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Blurred image(s).

Return type:

cvcuda.Tensor

cvcuda.tv.gaussian_noise(inpt: Tensor, mean: float = 0.0, sigma: float = 0.1, clip: bool = True, *, seed: int | None = None, stream: Stream | None = None) → Tensor[source]

Add independent Gaussian noise to every image element.

mean and sigma use normalized image units for uint8, float16, and float32 inputs. Reusing an explicit seed reproduces the same output; omitting it advances the random sequence.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s), uint8, float16, or float32 with 1 or 3 channels.

  • mean (float) – Mean of the sampled normal distribution.

  • sigma (float) – Non-negative standard deviation of the distribution.

  • clip (bool) – Clamp to [0, 255] for uint8 or [0, 1] for floating point. With False, uint8 wraps and floating-point output remains unbounded.

  • seed (int, optional) – Non-negative 64-bit per-call seed. Keyword-only.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Image(s) with added noise.

Return type:

cvcuda.Tensor

Raises:
  • TypeError – If seed is not an integer or None.

  • ValueError – If sigma is negative, seed is outside the uint64 range, or the input dtype or channel count is unsupported.

cvcuda.tv.grayscale_to_rgb(inpt: Tensor, *, stream: Stream | None = None) → Tensor[source]

Repeat a uint8, float16, or float32 grayscale channel to form RGB image(s).

If the input already has three or more channels, it is returned unchanged, mirroring torchvision’s behaviour.

Parameters:
  • inpt (cvcuda.Tensor) – Input image tensor (one or more channels).

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Three-channel RGB image(s), or the input unchanged when it already has three or more channels.

Return type:

cvcuda.Tensor

cvcuda.tv.horizontal_flip(inpt: Tensor, *, stream: Stream | None = None) → Tensor[source]

Flip image(s) horizontally (left-right).

Parameters:
Returns:

Image(s) flipped left-right.

Return type:

cvcuda.Tensor

cvcuda.tv.invert(inpt: Tensor, *, stream: Stream | None = None) → Tensor[source]

Invert the colors of an image: out = bound - in.

bound is the dtype maximum for unsigned-integer images and 1.0 for floating-point images.

Parameters:
Returns:

Output image(s).

Return type:

cvcuda.Tensor

cvcuda.tv.jpeg(image: Tensor, quality: int, *, stream: Stream | None = None) → Tensor[source]

Apply JPEG compression artifacts to image(s).

This simulates the lossy stages of JPEG compression, including chroma subsampling and block quantization. It returns an image tensor rather than encoded JPEG data.

Parameters:
  • image (cvcuda.Tensor) – Input uint8 image tensor with 1 or 3 channels in HWC, NHWC, CHW, or NCHW layout.

  • quality (int) – JPEG quality, from 1 (strongest distortion) to 100 (weakest).

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

JPEG-compressed image(s).

Return type:

cvcuda.Tensor

Raises:
  • TypeError – If quality is not an integer.

  • RuntimeError – If quality is outside [1, 100] or image is not uint8 with 1 or 3 channels.

cvcuda.tv.normalize(inpt: Tensor, mean: int | float | Sequence[float], std: int | float | Sequence[float], inplace: bool = False, *, stream: Stream | None = None) → Tensor[source]

Normalize image(s) with per-channel mean and standard deviation.

Computes (inpt - mean) / std. A one-element mean or std is applied to every channel. Float16, float32, and float64 inputs are supported.

Parameters:
  • inpt (cvcuda.Tensor) – Float16, float32, or float64 input image(s).

  • mean (float | list[float]) – Per-channel means.

  • std (float | list[float]) – Nonzero per-channel standard deviations.

  • inplace (bool, optional) – Write the result into inpt and return it. Defaults to False.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Normalized image(s).

Return type:

cvcuda.Tensor

Raises:
  • TypeError – If inpt is not floating point.

  • ValueError – If any value in std is zero.

cvcuda.tv.pad(inpt: Tensor, padding: int | Sequence[int], fill: int | float | Sequence[float] | None = None, padding_mode: str = 'constant', *, stream: Stream | None = None) → Tensor[source]

Pad image(s) on all sides.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • padding (int | list[int]) – A common border width, [horizontal, vertical], or [left, top, right, bottom].

  • fill (int | float | list[float], optional) – Constant fill value(s).

  • padding_mode (str, optional) – One of constant, edge, reflect, symmetric. Defaults to constant.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Padded image(s).

Return type:

cvcuda.Tensor

cvcuda.tv.permute_channels(inpt: Tensor, permutation: Sequence[int], *, stream: Stream | None = None) → Tensor[source]

Reorder image channels.

The output channel j receives input channel permutation[j]. Negative indices wrap from the end and repeated indices are allowed. For an empty input, only the permutation length is validated.

Parameters:
  • inpt (cvcuda.Tensor) – Input image tensor.

  • permutation (list[int]) – One source-channel index per output channel.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

The reordered tensor with the same metadata as inpt.

Return type:

cvcuda.Tensor

Raises:
  • ValueError – If permutation does not contain one index per channel.

  • IndexError – If an index is out of range for a non-empty input.

cvcuda.tv.perspective(inpt: Tensor, startpoints: Sequence[Sequence[int | float]] | None, endpoints: Sequence[Sequence[int | float]] | None, interpolation: InterpolationMode | Enum | str | int = InterpolationMode.BILINEAR, fill: int | float | Sequence[float] | None = None, coefficients: Sequence[float] | None = None, *, stream: Stream | None = None) → Tensor[source]

Apply a perspective transformation to image(s).

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • startpoints (list[list[int]]) – Four source corners (top-left, top-right, bottom-right, bottom-left).

  • endpoints (list[list[int]]) – Four destination corners, same order.

  • interpolation (InterpolationMode | str | int, optional) – Interpolation mode. Supports nearest and bilinear. Defaults to bilinear.

  • fill (int | float | list[float], optional) – Constant fill for exposed pixels.

  • coefficients (list[float], optional) – Precomputed (a..h) coefficients; overrides startpoints/endpoints.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Transformed image(s).

Return type:

cvcuda.Tensor

Raises:

ValueError – If interpolation is unsupported, the points do not describe four coordinate pairs, or coefficients does not contain eight values.

cvcuda.tv.posterize(inpt: Tensor, bits: int, *, stream: Stream | None = None) → Tensor[source]

Reduce each channel to its bits most-significant bits.

Lower-order bits are set to zero. bits=0 produces zeros and retaining the dtype bit width leaves the image unchanged. A floating-point image has no bit layout to keep, so it is quantized into 2 ** bits levels of its [0, 1] range instead, which is the same operation in that type’s value range.

Parameters:
  • inpt (cvcuda.Tensor) – Input unsigned-integer or floating-point image(s).

  • bits (int) – Number of high bits to keep, from 0 through the dtype bit width, or from 0 through 8 for floating-point images.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

cvcuda.tv.resize(inpt: Tensor, size: int | Sequence[int] | None, interpolation: InterpolationMode | Enum | str | int = InterpolationMode.BILINEAR, max_size: int | None = None, antialias: bool | None = True, *, stream: Stream | None = None) → Tensor[source]

Resize image(s) to a target size using cvcuda.tvresize().

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • size (int | list[int]) – Target size; a two-element [h, w] is exact, a scalar sets the shorter edge preserving aspect ratio.

  • interpolation (InterpolationMode | str | int, optional) – Interpolation mode. Supports nearest, nearest-exact, bilinear, and bicubic. Defaults to bilinear.

  • max_size (int, optional) – Cap for the longer edge when size is scalar.

  • antialias (bool, optional) – Apply an antialiasing filter when downscaling.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Resized image(s).

Return type:

cvcuda.Tensor

Raises:

NotImplementedError – If interpolation is unsupported.

cvcuda.tv.resized_crop(inpt: Tensor, top: int, left: int, height: int, width: int, size: int | Sequence[int], interpolation: InterpolationMode | Enum | str | int = InterpolationMode.BILINEAR, antialias: bool | None = True, *, stream: Stream | None = None) → Tensor[source]

Crop a region from image(s) then resize it to a target size.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • top (int) – Crop rectangle (rows from top, columns from left).

  • left (int) – Crop rectangle (rows from top, columns from left).

  • height (int) – Crop rectangle (rows from top, columns from left).

  • width (int) – Crop rectangle (rows from top, columns from left).

  • size (int | list[int]) – Target size for the resize.

  • interpolation (InterpolationMode | str | int, optional) – Interpolation mode. Supports nearest, nearest-exact, bilinear, and bicubic. Defaults to bilinear.

  • antialias (bool, optional) – Apply an antialiasing filter when downscaling.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Cropped-and-resized image(s).

Return type:

cvcuda.Tensor

Raises:

NotImplementedError – If interpolation is unsupported.

cvcuda.tv.rgb_to_grayscale(inpt: Tensor, num_output_channels: int = 1, *, stream: Stream | None = None) → Tensor[source]

Convert uint8, float16, or float32 image(s) to grayscale.

Accepts one-channel (already-grayscale) or three-channel RGB inputs, mirroring torchvision’s behaviour: a single-channel input is returned unchanged for num_output_channels=1 and replicated to three channels for num_output_channels=3.

Parameters:
  • inpt (cvcuda.Tensor) – Input one- or three-channel image tensor.

  • num_output_channels (int) – 1 (grayscale) or 3 (grayscale broadcast to RGB).

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Grayscale image(s) with one or three output channels.

Return type:

cvcuda.Tensor

Raises:

ValueError – If num_output_channels is not 1 or 3.

cvcuda.tv.rotate(inpt: Tensor, angle: float, interpolation: InterpolationMode | Enum | str | int = InterpolationMode.NEAREST, expand: bool = False, center: Sequence[int | float] | None = None, fill: int | float | Sequence[float] | None = None, *, stream: Stream | None = None) → Tensor[source]

Rotate image(s) by angle degrees counter-clockwise.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • angle (float) – Counter-clockwise rotation in degrees.

  • interpolation (InterpolationMode | str | int, optional) – Interpolation mode. Supports nearest and bilinear. Defaults to nearest.

  • expand (bool, optional) – Grow the output so the whole rotated image fits, instead of keeping the input extent. Defaults to False.

  • center (list[float], optional) – Center of rotation, origin top-left; defaults to the image center. Ignored for the expanded extent, as in torchvision.

  • fill (int | float | list[float], optional) – Constant fill for exposed pixels.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Rotated image(s).

Return type:

cvcuda.Tensor

Raises:

ValueError – If interpolation is unsupported.

cvcuda.tv.solarize(inpt: Tensor, threshold: float, *, stream: Stream | None = None) → Tensor[source]

Invert every pixel at or above threshold.

Pixels below the threshold are unchanged. Inversion uses the dtype maximum for unsigned integers and 1.0 for floating-point images.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • threshold (float) – Values greater than or equal to this value are inverted.

  • stream (cvcuda.Stream, optional) – Stream used to submit the operation.

Returns:

Output image(s).

Return type:

cvcuda.Tensor

cvcuda.tv.ten_crop(inpt: Tensor, size: int | Sequence[int], vertical_flip: bool = False, *, stream: Stream | None = None) → tuple[Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor][source]

Crop image(s) into five crops plus their flipped versions (ten crops).

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • size (int | list[int]) – Crop [height, width] (a scalar crops a square).

  • vertical_flip (bool, optional) – Flip vertically instead of horizontally for the second five crops.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

Five crops of the input followed by five crops

of its flipped copy.

Return type:

tuple[cvcuda.Tensor, …]

cvcuda.tv.to_dtype(inpt: ~cvcuda.Tensor, dtype: object = <class 'numpy.float32'>, scale: bool = False, *, stream: ~cvcuda.Stream | None = None) → Tensor[source]

Convert image(s) to a target dtype, optionally rescaling values.

With scale=False this is a plain dtype cast. With scale=True, integer and floating-point ranges are remapped, for example uint8 [0, 255] to float [0, 1]. dtype may be a NumPy dtype, a torch.dtype, or a dtype name.

Parameters:
  • inpt (cvcuda.Tensor) – Input image(s).

  • dtype (numpy.dtype | torch.dtype | str) – Target dtype.

  • scale (bool) – When True, rescale values across the dtype ranges.

  • stream (cvcuda.Stream, optional) – CUDA stream. Defaults to the current stream.

Returns:

inpt converted to the target dtype.

Return type:

cvcuda.Tensor

Raises:

TypeError – If dtype does not resolve to a supported CV-CUDA type.

cvcuda.tv.vertical_flip(inpt: Tensor, *, stream: Stream | None = None) → Tensor[source]

Flip image(s) vertically (up-down).

Parameters:
Returns:

Image(s) flipped up-down.

Return type:

cvcuda.Tensor