Commit 2dd83ad
committed
Fix make_gaussian_kernel truncated parameter unit mismatch (#8780)
`gaussian_1d`'s `truncated` parameter is a sigma multiplier (radius =
truncated × sigma), not a pixel radius. `make_gaussian_kernel` was
passing `kernel_size // 2` (pixel radius) directly, causing it to
generate a 2×sigma×(kernel_size//2)+1 element kernel — vastly larger
than needed. Slicing `[:kernel_size]` then kept only the extreme left
tail, producing a near-zero asymmetric kernel for any kernel_size > 3.
Replace the `gaussian_1d`-based implementation with a direct sampling
of exp(-0.5·x²/σ²) over the correct symmetric range, removing the
dependency on the confusing `truncated` semantics entirely.
Fixes: kernel_size=3 happened to work by coincidence (sigma=1 so
sigma×truncated=truncated), hiding the bug in existing tests.
Fixes: 8780
Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>1 parent daaedaa commit 2dd83ad
2 files changed
Lines changed: 35 additions & 7 deletions
File tree
- monai/losses
- tests/losses/image_dissimilarity
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
Lines changed: 29 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
116 | 135 | | |
117 | 136 | | |
118 | 137 | | |
| |||
138 | 157 | | |
139 | 158 | | |
140 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
141 | 169 | | |
142 | 170 | | |
143 | 171 | | |
| |||
0 commit comments