Fix make_gaussian_kernel truncated parameter for kernel_size > 3#8811
Fix make_gaussian_kernel truncated parameter for kernel_size > 3#8811atharvajoshi01 wants to merge 1 commit intoProject-MONAI:devfrom
Conversation
The truncated parameter was set to kernel_size // 2, but gaussian_1d interprets it as the number of standard deviations. With kernel_size=15 and sigma=5.0, this produced tail=35 (a 71-element kernel), which when sliced to kernel_size gave near-zero values. Fix: compute truncated as (kernel_size // 2) / sigma so that the resulting tail equals kernel_size // 2, producing a correctly-sized kernel with meaningful values.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughModified Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @atharvajoshi01 thanks for this fix. We had PR #8781 already open for it but it initially didn't mention the original issue so you wouldn't have seen it. I think it's equivalent to your solution, if you wouldn't mind please check that you agree with that. I think we would merge the other PR as it also has tests included. Sorry you spent time on this, we should have gotten to the other PR sooner. |
Fixes #8780.
make_gaussian_kernelpassedkernel_size // 2as thetruncatedparameter togaussian_1d. Butgaussian_1dinterpretstruncatedas the number of standard deviations, not the half-width in samples. It computestail = int(sigma * truncated).With
kernel_size=15,sigma=5.0,truncated=7:tail = 5.0 * 7 = 35→ kernel has 71 elements[:15]keeps only the far-left tail where values are near zeroFix: set
truncated = (kernel_size // 2) / sigmaso thattailequalskernel_size // 2, producing a correctly-sized kernel.