Fix convolution sampling for bounds smaller than the kernel radius
Merged
JI
3mo ago+143+143+012345678901234567890123456789-1-1-0123456789
Prerequisites
- I have written a descriptive pull-request title
- I have verified that there are no overlapping pull-requests open
- I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules :cop:.
- I have provided test coverage for my change (where applicable)
Description
This pull request improves the handling of border conditions in convolution operations when the image bounds are smaller than the kernel radius. It introduces a new method to ensure all sampling offsets are correctly folded into range for all border wrapping modes, and adds comprehensive tests to verify this behavior.
Border handling improvements
- Added the
CorrectBorderExactmethod inKernelSamplingMap.csto handle cases where the image bounds are smaller than the kernel radius, ensuring all offsets are folded exactly according to the selectedBorderWrappingMode. This prevents out-of-bounds access and guarantees correct sampling for small images. [1] [2] - Updated the logic in
CorrectBorderto callCorrectBorderExactwhen the bounds are no larger than the kernel radius, improving reliability for edge cases.
Testing enhancements
- Added a new test class
KernelSamplingMapTeststo verify that, for all border wrapping modes, sampling offsets stay within bounds when the image is smaller than the kernel radius. - Added a test in
GaussianBlurTestto ensure that applying a large-radius Gaussian blur to a solid-color image with small bounds leaves the color unchanged for all border modes, confirming correct border handling. - Included necessary using directives in
GaussianBlurTest.csto support the new tests.