Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hyunji
/
A-Performance-Evaluation-of-CNN-for-Brain-Age-Prediction-Using-Structural-MRI-Data
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Hyunji
2021-12-20 03:50:28 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d327569588730d19879ea525c610bbdb11d60975
d3275695
1 parent
aa2fd90d
transforms
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
3DCNN_VGGNet_2DResNet/transforms.py
3DCNN_VGGNet_2DResNet/transforms.py
0 → 100644
View file @
d327569
import
numpy
as
np
from
imgaug
import
augmenters
as
iaa
from
scipy.ndimage
import
interpolation
,
rotate
import
torch
class
ImgAugTranslation
(
object
):
"""Translation
Arg:
Pixels: number of pixels to apply translation to the image"""
def
__init__
(
self
,
pixels
):
n_pixels
=
int
(
pixels
)
self
.
aug
=
iaa
.
Affine
(
translate_px
=
(
-
n_pixels
,
n_pixels
))
def
__call__
(
self
,
img
):
img
=
np
.
array
(
img
)
return
self
.
aug
.
augment_image
(
img
)
class
ImgAugRotation
(
object
):
"""Rotation
Arg:
Degrees: number of degrees to rotate the image"""
def
__init__
(
self
,
degrees
):
n_degrees
=
float
(
degrees
)
self
.
aug
=
iaa
.
Affine
(
rotate
=
(
-
n_degrees
,
n_degrees
),
mode
=
'symmetric'
)
def
__call__
(
self
,
img
):
img
=
np
.
array
(
img
)
return
self
.
aug
.
augment_image
(
img
)
class
Translation
(
object
):
"""Translation"""
def
__init__
(
self
,
offset
,
order
=
0
,
isseg
=
False
,
mode
=
'nearest'
):
self
.
order
=
order
if
isseg
else
5
self
.
offset
=
offset
self
.
mode
=
'nearest'
if
isseg
else
'mirror'
def
__call__
(
self
,
img
):
return
interpolation
.
shift
(
img
,
self
.
offset
,
order
=
self
.
order
,
mode
=
self
.
mode
)
class
Rotation
(
object
):
"""Rotation"""
def
__init__
(
self
,
theta
,
order
=
0
,
isseg
=
False
,
mode
=
'nearest'
):
self
.
order
=
order
if
isseg
else
5
self
.
theta
=
float
(
theta
)
self
.
mode
=
'nearest'
if
isseg
else
'mirror'
def
__call__
(
self
,
img
):
return
rotate
(
img
,
self
.
theta
,
reshape
=
False
,
order
=
self
.
order
,
mode
=
self
.
mode
)
class
ToTensor
(
object
):
"""Convert ndarrays in sample to Tensors."""
def
__call__
(
self
,
sample
):
return
torch
.
from_numpy
(
np
.
asarray
(
sample
)
.
astype
(
np
.
float32
))
\ No newline at end of file
Please
register
or
login
to post a comment