imaging icon indicating copy to clipboard operation
imaging copied to clipboard

Add support for radius input parameter to Blur function

Open bgreenblatt opened this issue 4 years ago • 2 comments

I have a requirement to supply the radius instead of calculating it based on the sigma input. I implemented it like this:

-func Blur(img image.Image, sigma float64) *image.NRGBA {
+func Blur(img image.Image, sigma float64, radius int) *image.NRGBA {
        if sigma <= 0 {
                return Clone(img)
        }
 
-       radius := int(math.Ceil(sigma * 3.0))
+       if radius == 0 {
+               radius = int(math.Ceil(sigma * 3.0))
+       }

Let me know what you think.

bgreenblatt avatar Jan 07 '21 17:01 bgreenblatt

Indeed, it may be useful sometimes to control the radius parameter separately from the sigma, but this requires changing the signature of the function. This would break other people's code.

disintegration avatar Jan 09 '21 16:01 disintegration

Makes sense. Maybe better to add a new API that supports both parameters and has some code duplication

bgreenblatt avatar Jan 11 '21 15:01 bgreenblatt