Skip to content
Snippets Groups Projects
Commit 1aafeb43 authored by Daniel CARRON's avatar Daniel CARRON :b: Committed by André Anjos
Browse files

[transforms] Transform to crop multiple images at once

parent d7e6d5fa
No related branches found
No related tags found
1 merge request!46Create common library
...@@ -14,7 +14,7 @@ def crop_image_to_mask(img: torch.Tensor, mask: torch.Tensor) -> torch.Tensor: ...@@ -14,7 +14,7 @@ def crop_image_to_mask(img: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
Parameters Parameters
---------- ----------
img img
The image to crop. The image to crop, of shape channels x height x width.
mask mask
The boolean mask to use for cropping. The boolean mask to use for cropping.
...@@ -41,6 +41,25 @@ def crop_image_to_mask(img: torch.Tensor, mask: torch.Tensor) -> torch.Tensor: ...@@ -41,6 +41,25 @@ def crop_image_to_mask(img: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
return img[:, top:bottom, left:right] return img[:, top:bottom, left:right]
def crop_multiple_images_to_mask(
images: list[torch.Tensor], mask: torch.Tensor
) -> list[torch.Tensor]:
"""Apply crop_images_to_mask on multiple images.
Parameters
----------
images
List of images to crop, of shape channels x height x width.
mask
The boolean mask to use for cropping.
Returns
-------
A list of cropped images.
"""
return [crop_image_to_mask(img, mask) for img in images]
def resize_max_side(tensor: torch.Tensor, max_side: int) -> torch.Tensor: def resize_max_side(tensor: torch.Tensor, max_side: int) -> torch.Tensor:
"""Resize image based on the longest side while keeping the aspect ratio. """Resize image based on the longest side while keeping the aspect ratio.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment