Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mednet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
medai
software
mednet
Commits
1aafeb43
Commit
1aafeb43
authored
9 months ago
by
Daniel CARRON
Committed by
André Anjos
8 months ago
Browse files
Options
Downloads
Patches
Plain Diff
[transforms] Transform to crop multiple images at once
parent
d7e6d5fa
No related branches found
No related tags found
1 merge request
!46
Create common library
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mednet/libs/common/models/transforms.py
+20
-1
20 additions, 1 deletion
src/mednet/libs/common/models/transforms.py
with
20 additions
and
1 deletion
src/mednet/libs/common/models/transforms.py
+
20
−
1
View file @
1aafeb43
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment