| Total Complexity | 4 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from torchio.data.subject import Subject |
||
| 2 | |||
| 3 | from ...transform import Transform |
||
| 4 | |||
| 5 | |||
| 6 | class RandomBiasFieldDenoise(Transform): |
||
| 7 | """ |
||
| 8 | Simple placeholder transform that simulates denoising after bias field |
||
| 9 | correction by blending voxel intensities toward the mean value. |
||
| 10 | |||
| 11 | Parameters: |
||
| 12 | noise_reduction_factor (float): Strength of denoising (0-1). |
||
| 13 | """ |
||
| 14 | |||
| 15 | def __init__(self, noise_reduction_factor: float = 0.1, **kwargs): |
||
| 16 | super().__init__(**kwargs) |
||
| 17 | self.noise_reduction_factor = noise_reduction_factor |
||
| 18 | |||
| 19 | def apply_transform(self, subject: Subject) -> Subject: |
||
| 20 | for _, image in subject.get_images_dict(intensity_only=True).items(): |
||
| 21 | tensor = image.data.float() |
||
| 22 | |||
| 23 | # Basic denoising by shifting toward mean intensity |
||
| 24 | mean_val = tensor.mean() |
||
| 25 | tensor = (tensor * (1 - self.noise_reduction_factor)) + ( |
||
| 26 | mean_val * self.noise_reduction_factor |
||
| 27 | ) |
||
| 28 | |||
| 29 | image.set_data(tensor) |
||
| 30 | |||
| 31 | return subject |
||
| 32 | |||
| 33 | def __repr__(self): |
||
| 34 | return f'{self.__class__.__name__}(noise_reduction_factor={self.noise_reduction_factor})' |
||
| 35 |