Skip to content

Commit

Permalink
Fix Blur using only the first standard deviation (#772)
Browse files Browse the repository at this point in the history
* Fix Blur using only the first standard deviation

Fixes #769.

* Use the same Gaussian kernel for all channels
  • Loading branch information
fepegar authored Dec 7, 2021
1 parent 3cebdec commit 68755fb
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions torchio/transforms/augmentation/intensity/random_blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import scipy.ndimage as ndi

from ....utils import to_tuple
from ....typing import TypeData, TypeTripletFloat, TypeSextetFloat
from ....data.subject import Subject
from ... import IntensityTransform
Expand Down Expand Up @@ -40,9 +39,9 @@ def __init__(

def apply_transform(self, subject: Subject) -> Subject:
arguments = defaultdict(dict)
for name, image in self.get_images_dict(subject).items():
stds = [self.get_params(self.std_ranges) for _ in image.data]
arguments['std'][name] = stds
for name in self.get_images_dict(subject):
std = self.get_params(self.std_ranges)
arguments['std'][name] = std
transform = Blur(**self.add_include_exclude(arguments))
transformed = transform(subject)
return transformed
Expand Down Expand Up @@ -72,15 +71,15 @@ def __init__(
self.args_names = ('std',)

def apply_transform(self, subject: Subject) -> Subject:
std = self.std
stds = self.std
for name, image in self.get_images_dict(subject).items():
if self.arguments_are_dict():
std = self.std[name]
stds = to_tuple(std, length=len(image.data))
stds = self.std[name]
stds_channels = np.tile(stds, (image.num_channels, 1))
transformed_tensors = []
for std, tensor in zip(stds, image.data):
for std, channel in zip(stds_channels, image.data):
transformed_tensor = blur(
tensor,
channel,
image.spacing,
std,
)
Expand Down

0 comments on commit 68755fb

Please sign in to comment.