Conversation
|
I don't think panicking on zero or close-to-zero kernel sizes/sigmas is the best solution here. As sigma approaches zero, the image gets less and less blurred, so at sigma=0 the image shouldn't be blurred at all. I believe we should simply return an unmodified copy of the input image for sigmas below some threshold. (This is what OpenCV does too IIRC.) Not sure what the behavior should be for sigma=NaN and sigma<0. Both panicking and returning the image unmodified seem fine to me. |
|
Sigma 0 is singularity https://en.wikipedia.org/wiki/Gaussian_blur, to avoid forcing user to set any sigma we have convenience methods. Subnormals also have almost no point, since we're using f32 for the kernel; kernel computation will underflow, so the result is signed zero, so the convolving result is signed zero as well, with underflow which should be signalled. I don't think handling this in image library make sense. |
|
Panicking might be fine if we did it early. Panics further down the call stack should not be error handling. At least they should to be documented on the public entry points which I guess might be painful enough here to be convincing. Maybe we use a validating constructor instead? I do think that we don't want to silently swallow NaN sigma entirely. Negative could be treated with saturating to zero in my opinion, it isn't inconvenient if the passed sigma is calculated and the algorithm for calculating it is not entirely safe against floating-point rounding giving impossible, tiny negative values. |
|
Well, it appeared we're solving problem that doesn't exists since we didn't add public arbitrary constructor. I added one and comments. PTAL
I didn't exactly get actually where to do it, because in convenience methods except |
That doesn't mean the operation doesn't have a limit. If I'm reading the code correctly, the generated kernels are normalized to have a sum of 1. This means that all kernels of size 1 are simply This should also mean that a bunch of small kernel sizes all behave identically. For |
|
This is not a bug it's plan. There was no plan to expose complete filtering API, only some reasonable defaults. As well OpenCV did because in the most cases no one needs that. And if anyone needs to handle different filtering kernels, they do need different implementation and API. |
It's not reasonable though. No one would expect that Also, I just tested it and small blur radii are completely broken. Any radius <= 0.5 performs no blur and moves all pixel 1 to the right. This should be addressed in a separate PR, though. |
|
Actually, we're fixing a problem that never existed, and we might just silently introduce one, so I'll go ahead and close this.
I personally don't think so, this method does exactly what is does. If 0.49 rounds to kernel size 1, so I tend to think that user should handle this. I don't see why it should magically resolve 0.49 to a kernel of size 3 without any reason. |
|
I haven't been following the full context in this thread, but it seems [edit: potentially] reasonable to me to always use a kernel size >=3 if kernel size 1 is just a no-op |
|
I see this completely differently:
Please, if someone wants to discuss problems or questions that is not related to a PR; I don't have an issue with that, but consider opening an issue instead of creating a long discussion about things that are not supposed to be addressed in the PR. Anyone interested will be able to find the problem in the issues. |

As discussed #2838