-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
The bias field generated by RandBiasField._generate_random_field (link) should be exponentiated, as done so in NiftyNet's implementation.
To Reproduce
import matplotlib.pyplot as plt
import numpy as np
from monai.transforms import RandBiasField
rand_bias_field = RandBiasField()
arr = np.ones((1,100,100))
bias_field = rand_bias_field(arr)
plt.figure(figsize=(12,6))
plt.subplot(121)
plt.imshow(bias_field[0])
plt.subplot(122)
plt.hist(bias_field.flatten())
plt.show()
As shown on the histogram on the right, the values generated by the bias field are around 0 and can also be negative. This is not a proper bias field and multiplying an image by this bias field may invert values.
Expected behavior
The bias field should have values around 1. This is usually done by exponentiating the bias field since the bias field generated from the polynomial basis function is actually the log-transformed bias field (Refer to last equation in section 3.1.1 and the NiftyNet implementation of RandBiasField (linked above).
import matplotlib.pyplot as plt
import numpy as np
from monai.transforms import RandBiasField
rand_bias_field = RandBiasField()
arr = np.ones((1,100,100))
bias_field = np.exp(rand_bias_field(arr))
plt.figure(figsize=(12,6))
plt.subplot(121)
plt.imshow(bias_field[0])
plt.subplot(122)
plt.hist(bias_field.flatten())
plt.show()
Additional comments
Are there any plans to make a batched Tensor-compatible implementation of RandBiasField so that this transform can theoretically be done on the GPU after batching? At the moment, the only critical numpy dependencies are the calls to np.polynomial.legendre.leggrid2d and np.polynomial.legendre.leggrid3d, but these can be easily implemented using PyTorch.

