resizing
sleap_nn.data.resizing
¶
This module implements image resizing and padding.
Functions:
Name | Description |
---|---|
apply_pad_to_stride |
Pad an image to meet a max stride constraint. |
apply_resizer |
Rescale image and keypoints by a scale factor. |
apply_sizematcher |
Apply scaling and padding to image to (max_height, max_width) shape. |
find_padding_for_stride |
Compute padding required to ensure image is divisible by a stride. |
resize_image |
Rescale an image by a scale factor. |
apply_pad_to_stride(image, max_stride)
¶
Pad an image to meet a max stride constraint.
This is useful for ensuring there is no size mismatch between an image and the output tensors after multiple downsampling and upsampling steps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Tensor
|
Single image tensor of shape (..., channels, height, width). |
required |
max_stride
|
int
|
Scalar integer specifying the maximum stride that the image must be
divisible by. This is the ratio between the length of the image and the
length of the smallest tensor it is converted to. This is typically
|
required |
Returns:
Type | Description |
---|---|
Tensor
|
The input image with 0-padding applied to the bottom and/or right such that the
new shape's height and width are both divisible by |
Source code in sleap_nn/data/resizing.py
apply_resizer(image, instances, scale=1.0)
¶
Rescale image and keypoints by a scale factor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Tensor
|
Image tensor of shape (..., channels, height, width) |
required |
instances
|
Tensor
|
Keypoints tensor. |
required |
scale
|
float
|
Factor to resize the image dimensions by, specified as a float scalar. Default: 1.0. |
1.0
|
Returns:
Type | Description |
---|---|
Tuple with resized image and corresponding keypoints. |
Source code in sleap_nn/data/resizing.py
apply_sizematcher(image, max_height=None, max_width=None)
¶
Apply scaling and padding to image to (max_height, max_width) shape.
Source code in sleap_nn/data/resizing.py
find_padding_for_stride(image_height, image_width, max_stride)
¶
Compute padding required to ensure image is divisible by a stride.
This function is useful for determining how to pad images such that they will not have issues with divisibility after repeated pooling steps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_height
|
int
|
Scalar integer specifying the image height (rows). |
required |
image_width
|
int
|
Scalar integer specifying the image height (columns). |
required |
max_stride
|
int
|
Scalar integer specifying the maximum stride that the image must be divisible by. |
required |
Returns:
Type | Description |
---|---|
Tuple[int, int]
|
A tuple of (pad_height, pad_width), integers with the number of pixels that the image would need to be padded by to meet the divisibility requirement. |
Source code in sleap_nn/data/resizing.py
resize_image(image, scale)
¶
Rescale an image by a scale factor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Tensor
|
Single image tensor of shape (..., channels, height, width). |
required |
scale
|
float
|
Factor to resize the image dimensions by, specified as a float scalar. |
required |
Returns:
Type | Description |
---|---|
The resized image tensor of the same dtype but scaled height and width. |