Skip to content

Commit

Permalink
added resample
Browse files Browse the repository at this point in the history
  • Loading branch information
bmandracchia committed Sep 2, 2024
1 parent 36036cb commit 660becb
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 64 deletions.
1 change: 1 addition & 0 deletions bioMONAI/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'lib_path': 'bioMONAI'},
'syms': { 'bioMONAI.callbacks': {'bioMONAI.callbacks.foo': ('callbacks.html#foo', 'bioMONAI/callbacks.py')},
'bioMONAI.core': { 'bioMONAI.core.attributesFromDict': ('core.html#attributesfromdict', 'bioMONAI/core.py'),
'bioMONAI.core.img2Tensor': ('core.html#img2tensor', 'bioMONAI/core.py'),
'bioMONAI.core.img2float': ('core.html#img2float', 'bioMONAI/core.py')},
'bioMONAI.data': { 'bioMONAI.data.BioImage': ('data.html#bioimage', 'bioMONAI/data.py'),
'bioMONAI.data.BioImage.__repr__': ('data.html#bioimage.__repr__', 'bioMONAI/data.py'),
Expand Down
6 changes: 5 additions & 1 deletion bioMONAI/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.

# %% auto 0
__all__ = ['attributesFromDict', 'img2float']
__all__ = ['attributesFromDict', 'img2float', 'img2Tensor']

# %% ../nbs/00_core.ipynb 4
from torch import Tensor as torchTensor
Expand Down Expand Up @@ -34,3 +34,7 @@ def attributesFromDict(d):
# %% ../nbs/00_core.ipynb 9
def img2float(image, force_copy=False):
return util.img_as_float(image, force_copy=force_copy)

# %% ../nbs/00_core.ipynb 10
def img2Tensor(image):
return torchTensor(img2float(image))
14 changes: 7 additions & 7 deletions bioMONAI/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# %% ../nbs/05_transforms.ipynb 3
from fastai.vision.all import *
from fastai.data.all import *
from monai.transforms import SpatialCrop, Flip, Rotate90
from monai.transforms import SpatialCrop, Flip, Rotate90, Spacing
from numpy import percentile, isscalar, float32 as np_float32

# %% ../nbs/05_transforms.ipynb 11
# %% ../nbs/05_transforms.ipynb 13
def _process_sz(size, ndim=3):
if isinstance(size,int):
size=(size,)*ndim
Expand All @@ -20,7 +20,7 @@ def _get_sz(x):
if not isinstance(x, Tensor): return fastuple(x.size)
return fastuple(getattr(x, 'img_size', getattr(x, 'sz', (x.shape[1:])))) # maybe it should swap x and y axes

# %% ../nbs/05_transforms.ipynb 14
# %% ../nbs/05_transforms.ipynb 16
class RandCrop2D(RandTransform):
"Randomly crop an image to `size`"
split_idx,order = None,1
Expand Down Expand Up @@ -50,7 +50,7 @@ def before_call(self,
def encodes(self, x):
return SpatialCrop(roi_center=self.ctr, roi_size=self.size, lazy=self.lazy)(x)

# %% ../nbs/05_transforms.ipynb 15
# %% ../nbs/05_transforms.ipynb 17
class RandCropND(RandTransform):
"""
Randomly crops an ND image to a specified size.
Expand Down Expand Up @@ -103,7 +103,7 @@ def encodes(self, x):
return SpatialCrop(roi_start=self.tl, roi_end=self.br, lazy=self.lazy)(x)


# %% ../nbs/05_transforms.ipynb 17
# %% ../nbs/05_transforms.ipynb 19
class RandCropND_T(RandTransform):
"""
Randomly crops an ND image to a specified size.
Expand Down Expand Up @@ -166,7 +166,7 @@ def encodes(self, x):
return cropped_img


# %% ../nbs/05_transforms.ipynb 19
# %% ../nbs/05_transforms.ipynb 21
class RandFlip(RandTransform):
"""
Randomly flips an ND image over a specified axis.
Expand Down Expand Up @@ -199,7 +199,7 @@ def encodes(self, x):
else:
return x

# %% ../nbs/05_transforms.ipynb 21
# %% ../nbs/05_transforms.ipynb 23
class RandRot90(RandTransform):
"""
Randomly rotate an ND image by 90 degrees in the plane specified by axes.
Expand Down
13 changes: 12 additions & 1 deletion nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@
" return util.img_as_float(image, force_copy=force_copy)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"def img2Tensor(image):\n",
" return torchTensor(img2float(image))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -118,7 +129,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
Expand Down
206 changes: 151 additions & 55 deletions nbs/05_transforms.ipynb

Large diffs are not rendered by default.

0 comments on commit 660becb

Please sign in to comment.