{"task": {"agent_timeout": 3000, "task": "project-monai__monai-2645", "verifier_timeout": 30000, "instruction": "RandBiasField missing np.exp\n**Describe the bug**\nThe bias field generated by `RandBiasField._generate_random_field` ([link](https://github.com/Project-MONAI/MONAI/blob/0ad9e73639e30f4f1af5a1f4a45da9cb09930179/monai/transforms/intensity/array.py#L434)) should be exponentiated, as done so in [NiftyNet's implementation](https://github.com/NifTK/NiftyNet/blob/935bf4334cd00fa9f9d50f6a95ddcbfdde4031e0/niftynet/layer/rand_bias_field.py#L99).\n\n**To Reproduce**\n```\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom monai.transforms import RandBiasField\n\nrand_bias_field = RandBiasField()\narr = np.ones((1,100,100))\n\nbias_field = rand_bias_field(arr)\n\nplt.figure(figsize=(12,6))\nplt.subplot(121)\nplt.imshow(bias_field[0])\n\nplt.subplot(122)\nplt.hist(bias_field.flatten())\nplt.show()\n```\n![image](https://user-images.githubusercontent.com/20669652/126690750-2d55cbcc-42ee-44bf-828d-7b2738a5b2dd.png)\n\nAs 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.\n\n**Expected behavior**\nThe 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](https://www.sciencedirect.com/science/article/pii/S1361841517300257?via%3Dihub) and the NiftyNet implementation of RandBiasField (linked above). \n\n```\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom monai.transforms import RandBiasField\n\nrand_bias_field = RandBiasField()\narr = np.ones((1,100,100))\n\nbias_field = np.exp(rand_bias_field(arr))\n\nplt.figure(figsize=(12,6))\nplt.subplot(121)\nplt.imshow(bias_field[0])\n\nplt.subplot(122)\nplt.hist(bias_field.flatten())\nplt.show()\n```\n\n![image](https://user-images.githubusercontent.com/20669652/126691848-dd9838a2-eb0f-4dca-8960-a13ef55113fc.png)\n\n**Additional comments**\nAre 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.\n", "memory": "8192m", "runnable": false, "difficulty": "hard", "language": "", "cpus": 1, "instruction_truncated": false, "category": "debugging", "compose": false, "has_solution": true, "oracle": null, "docker_image": "", "taskset": "swegym", "tags": ["debugging", "swe-bench"]}, "runs": []}