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
800d5298
Commit
800d5298
authored
1 year ago
by
Daniel CARRON
Committed by
André Anjos
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Make ElastiCDeformation work with both greayscale and rgb images
parent
38fcac12
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Making use of LightningDataModule and simplification of data loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ptbench/data/transforms.py
+22
-7
22 additions, 7 deletions
src/ptbench/data/transforms.py
with
22 additions
and
7 deletions
src/ptbench/data/transforms.py
+
22
−
7
View file @
800d5298
...
@@ -46,13 +46,15 @@ class ElasticDeformation:
...
@@ -46,13 +46,15 @@ class ElasticDeformation:
def
__call__
(
self
,
img
):
def
__call__
(
self
,
img
):
if
random
.
random
()
<
self
.
p
:
if
random
.
random
()
<
self
.
p
:
img
=
transforms
.
ToPILImage
()(
img
)
assert
img
.
ndim
==
3
# Input tensor is of shape C x H x W
# If the tensor only contains one channel, this conversion results in H x W.
# With 3 channels, we get H x W x C
img
=
transforms
.
ToPILImage
()(
img
)
img
=
numpy
.
asarray
(
img
)
img
=
numpy
.
asarray
(
img
)
assert
img
.
ndim
==
2
shape
=
img
.
shape
[:
2
]
shape
=
img
.
shape
dx
=
(
dx
=
(
gaussian_filter
(
gaussian_filter
(
...
@@ -81,9 +83,22 @@ class ElasticDeformation:
...
@@ -81,9 +83,22 @@ class ElasticDeformation:
numpy
.
reshape
(
y
+
dy
,
(
-
1
,
1
)),
numpy
.
reshape
(
y
+
dy
,
(
-
1
,
1
)),
]
]
result
=
numpy
.
empty_like
(
img
)
result
=
numpy
.
empty_like
(
img
)
result
[:,
:]
=
map_coordinates
(
img
[:,
:],
indices
,
order
=
self
.
spline_order
,
mode
=
self
.
mode
if
img
.
ndim
==
2
:
).
reshape
(
shape
)
result
[:,
:]
=
map_coordinates
(
img
[:,
:],
indices
,
order
=
self
.
spline_order
,
mode
=
self
.
mode
).
reshape
(
shape
)
else
:
for
i
in
range
(
img
.
shape
[
2
]):
result
[:,
:,
i
]
=
map_coordinates
(
img
[:,
:,
i
],
indices
,
order
=
self
.
spline_order
,
mode
=
self
.
mode
,
).
reshape
(
shape
)
return
transforms
.
ToTensor
()(
PIL
.
Image
.
fromarray
(
result
))
return
transforms
.
ToTensor
()(
PIL
.
Image
.
fromarray
(
result
))
else
:
else
:
return
img
return
img
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