disintegration / imaging

Imaging is a simple image processing package for Go
MIT License
5.3k stars 443 forks source link

Add support for radius input parameter to Blur function #135

Open bgreenblatt opened 3 years ago

bgreenblatt commented 3 years ago

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.

disintegration commented 3 years ago

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.

bgreenblatt commented 3 years ago

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