Comments (8)
I think I solved it by implementing a custom transform, wrapping around it! :)
Thanks for your help!
from torchio import Subject, LabelMap, ScalarImage, RandomAffine
...
class tio_deforms(MapTransform):
"""
# wrapper for tio affine transformation
"""
def __init__(
self,
keys: KeysCollection,
# spatial_size: Union[Sequence[int], int],
) -> None:
"""
Args:
keys: keys of the corresponding items to be transformed.
See also: :py:class:`monai.transforms.compose.MapTransform`
spatial_size: the spatial size of output data after padding.
If its components have non-positive values, the corresponding size of input image will be used.
method: {``"symmetric"``, ``"end"``}
Pad image symmetric on every side or only pad at the end sides. Defaults to ``"symmetric"``.
mode: {``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``, ``"mean"``,
``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``}
One of the listed string values or a user supplied function. Defaults to ``"constant"``.
See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html
It also can be a sequence of string, each element corresponds to a key in ``keys``.
"""
super().__init__(keys)
def __call__(self, data: Mapping[Hashable, np.ndarray]) -> Dict[Hashable, np.ndarray]:
d = dict(data)
subject = Subject(
images=ScalarImage(tensor=d["images"]), # this class is new
label=LabelMap(tensor=d["label"]),
)
raf = RandomAffine(scales=(0.75, 1.25), degrees=20, keys=["images", "label"], p=1)
transformed = raf(subject)
d["images"] = transformed["images"].numpy()
d["label"] = transformed["label"].numpy()
return d
from tutorials.
Hi @neuronflow ,
Thanks for your experiments with MONAI.
May I know which transforms
do you use here? For spatial transforms in MONAI, you can set different interpolation methods for different keys, for example:
Spacingd(keys=["image", "label"], pixdim=(1.5, 1.5, 2.0), mode=("bilinear", "nearest")),
Thanks.
from tutorials.
To apply some interpolation to label maps, I would suggest converting them to one-hot encoded format and apply whatever mode you use with the images, afterwards reconstituting the original label map with argmax. Usually this produces good results with smooth edges and does not introduce holes in between adjacent labels. We might need to work on specific transforms to do these conversions however.
from tutorials.
Thanks for the quick responses, for native transforms it works as @Nic-Ma suggested. My question is how to make it work for third party party transforms. Here an example from torchio:
from torchio.transforms import (
# spatial
RandomAffine,
RandomElasticDeformation,
}
...
# these transforms deform / rotate the whole image and should therefore also affect labels
RandomAffine(scales=(0.85, 1.15), degrees=(13), image_interpolation="bspline", p=1, keys=["images", "segs"]),
RandomElasticDeformation(image_interpolation=("bspline"), p=1, keys=["images", "segs"]),
...
Unlike for the spatial MONAI transforms I can only supply a single string and not a tuple for the image_interpolation
parameter.
My labels are already one-hot encoded. Applying argmax after the interpolation is certainly an option. Is there a transform already doing that or should I implement my own?
from tutorials.
any news on this? I also asked in the torchio forums:
fepegar/torchio#221 (comment)
I don't know how I can apply the suggested solution in the MONAI universe
Meanwhile I tried to replace the tio RandomAffine, and RandomElasticDeformation with the MONAI equivalents. I experimented with different sigma_range
and magnitude_range
values. Is there a rule of thump how to find good default values?
from tutorials.
Cool! sounds good.
from tutorials.
Hi @neuronflow, Are there benefits to using TorchIO in addition to the transforms provided by MONAI? I'm looking at both libraries for augmentation. Thanks in advance!
from tutorials.
from my POV this really depends on your use case, I appreciate especially the "medical" augmentations from torchio as they are more "plausible" than many artificial image distortions.
that being said, I did not observe massive performance gains by using these torchio transforms and never carefully studied their effects.
from tutorials.
Related Issues (20)
- unrecognized arguments `local-rank` in "brats_training_ddp.py"
- FileNotFoundError in "acceleration/TensorRT_inference_acceleration.ipynb"
- KeyError in "reconstruction/MRI_reconstruction/unet_demo/inference.ipynb"
- swin_unetr_btcv_segmentation_3d: pre trained model download link broken HOT 4
- Link for Installation of MONAI Generative Models gives 404 error
- AutoRunner demo needs to set auto_scale_allowed to False HOT 1
- Incorporating ONNX Support into Brain Tumor Segmentation Example HOT 1
- Getting cls_logits NaN of Inf during training HOT 1
- Decollate_batch() should be used with LoadImaged or LoadImage(image_only= "False") with dictionary_based input HOT 1
- module 'cv2.dnn' has no attribute 'DictValue'
- ImportError: libGL.so.1: cannot open shared object file: No such file or directory
- Kernel hangs in "TCIA_PROSTATEx_Prostate_MRI_Anatomy_Model.ipynb" HOT 11
- nbclient.exceptions.DeadKernelError: Kernel died in ./modules/3d_image_transforms.ipynb HOT 7
- Issue with multi-GPU support in Auto3DSeg on Windows HOT 1
- the argument needed to change the default directory in pathology/tumor_detection/README.MD
- please upload more famous diffusion model about image to image,thanks HOT 1
- Certificate verify failed when downloading OASIS data
- monailabel tutorials contain broken and outdated links to Orthanc HOT 2
- IndexError in modules/resample_benchmark.ipynb HOT 1
- Auto3DSeg to test data for segmentation of the Lung HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tutorials.