question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error using RandomNoise and RandomBlur on 2D images

See original GitHub issue

🐛Bug 2d transform of my images is not working resulting in crash

To reproduce

I try to use torchio transforms on 2d sattelite images, I have only 1 input channel:

# << INTENSITY augmentations >>
tio_intensity_prob = 0.2

_tio_noise_tfs = Compose([
    RandomBlur(p=tio_intensity_prob, keys=["images"]),
    RandomNoise(p=tio_intensity_prob, keys=["images"]),
])

Expected behavior transformed images

Actual behavior crash, I added dimensions and shape of the tensor to the error msg

Original Traceback (most recent call last):                                                                                          
  File "/home/florian/miniconda3/envs/sat/lib/python3.8/site-packages/monai/transforms/utils.py", line 361, in apply_transform       
    return transform(data)                                                                                                           
  File "/home/florian/miniconda3/envs/sat/lib/python3.8/site-packages/torchio/transforms/transform.py", line 68, in __call__         
    subject = data_parser.get_subject()                                                                                              
  File "/home/florian/miniconda3/envs/sat/lib/python3.8/site-packages/torchio/transforms/data_parser.py", line 66, in get_subject    
    subject = self._get_subject_from_dict(self.data, self.keys)                                                                      
  File "/home/florian/miniconda3/envs/sat/lib/python3.8/site-packages/torchio/transforms/data_parser.py", line 134, in _get_subject_$rom_dict
    value = ScalarImage(tensor=value)
  File "/home/florian/miniconda3/envs/sat/lib/python3.8/site-packages/torchio/data/image.py", line 516, in __init__
    super().__init__(*args, **kwargs)
  File "/home/florian/miniconda3/envs/sat/lib/python3.8/site-packages/torchio/data/image.py", line 124, in __init__
    tensor = self._parse_tensor(tensor)
  File "/home/florian/miniconda3/envs/sat/lib/python3.8/site-packages/torchio/data/image.py", line 364, in _parse_tensor
    raise ValueError(
ValueError: ('Input tensor must be 4D, but has these dimensions:', 3, torch.Size([1, 512, 512]))

System info

Output of python <(curl -s https://raw.githubusercontent.com/fepegar/torchio/master/print_system.py):

(sat) florian@ibbm_giga:~/satellite_one$ python <(curl -s https://raw.githubusercontent.com/fepegar/torchio/master/print_system.py)
If you use TorchIO for your research, please cite the following paper:
Pérez-García et al., TorchIO: a Python library for efficient loading,
preprocessing, augmentation and patch-based sampling of medical images
in deep learning. Credits instructions: https://torchio.readthedocs.io/#credits

Platform: Linux-4.15.0-144-generic-x86_64-with-glibc2.10
TorchIO:  0.18.1
PyTorch:  1.7.0+cu110
NumPy:    1.18.1
Python:   3.8.5 (default, Sep  4 2020, 07:30:14) 
[GCC 7.3.0]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
neuronflowcommented, Jul 23, 2021

Sorry, for the late response and thanks for clarifying 😃

1reaction
neuronflowcommented, Jul 7, 2021

Yes, thank you. In the meantime I solved it like this with some MONAI transforms:

_tio_tfs = Compose([
    # we need to add and remove channel with Monai to use the torchio transforms
    AddChanneld(keys=only_images),
    _tio_noise_tfs,
    _tio_artefact_tfs,
    SqueezeDimd(keys=only_images)
])

I still believe “native” 2D support would be good enhancement 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blurring Images – Image Processing with Python
The Gaussian blur is a way to apply a low-pass filter in skimage. It is often used to remove Gaussian (i. e., random)...
Read more >
Add noise to image - MATLAB imnoise - MathWorks
This MATLAB function adds zero-mean, Gaussian white noise with variance of 0.01 to grayscale image I.
Read more >
Removing blur from images – deconvolution and using ...
In this post, we'll have a look at the idea of removing blur from images, videos, or games through a process called “deconvolution”....
Read more >
2022 Adding and Filtering Random Noise (Median ... - YouTube
How to add Random Noise to an image in MATLAB ! ... 2022 How to Blur an Image with an Average Mask in...
Read more >
Python code to add random Gaussian noise on images · GitHub
Python code to add random Gaussian noise on images - add_gaussian_noise.py. ... gaussian noise multiplied then added over image: noise increases with image...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found