Fixes initial values for erode and dilate #1547
Conversation
|
@pavanky I wish I saw the PR before it got merged...
out = dilate(in, filter);
out(isInf(out)) = 0;If we use So, I was thinking, ideally we should let the user pass an optional template<typename T, bool IsDilation>
void morph(Array<T> out, Array<T> const in, Array<T> const mask, T missingValue)
{
}
template<typename T, bool IsDilation>
void morph(Array<T> out, Array<T> const in, Array<T> const mask)
{
T missingValue = ... // -inf/inf for floats, min/max for integrals
morph(out, int, mask, missingValue);
}
Note that, for the first function, since the passed T filterResult = init;
bool missing = true;
for (wj) {
for (wi) {
if (...) {
missing = false;
// ...
}
}
}
outData[ getIdx(ostrides, i, j) ] = missing ? missingValue : filterResult;The nice thing about having this default out = dilate(in, filter, 0); // no need to worry about replacing inf or max anymore |
|
BTW, these "missing values" are not really some strange corner case. They can happen very often near the boundaries of the input array, because near the boundaries, part of the filter falls outside of the array, and the rest could easily have all zeros. |
|
This is an easy fix. I can change the init value to be +/- infinity for float types in our Passing an additional parameter now will either break the API or will need implementing a new function. |
|
Also changing the value from max to infinity does not break other functions where we are using this functor. This will be the proper and consistent fix. |
|
@vakopian Thanks for pointing out the flaw btw. If you agree that using inifnity is a fair solution, I'll go ahead and do that. |
|
@pavanky of course, let's start by changing it to infinity. We can perhaps add the additional parameter/extra methods in a later release. BTW, is there a chance this fix will be in a 3.3.3 release? |
|
@vakopian There isn't going to be a 3.3.3. The next release will be 3.4 and it should be out very soon. |
|
@pavanky thanks for the information. While we're on the subject of I've looked at the CPU implementation of |
|
@vakopian The CPU backend is not at all optimized. It runs on a single core and is not vectorized. It exists as a fallback solution. This will change in the future. For now, if you want a better performing CPU version try out with the intel opencl driver installed. |
|
@pavanky: sure, I understand that we can get better performance with vectorization and such, but I was thinking there might be purely algorithmic ways to improve this. After some digging around, I think we could achieve a big performance improvement by first pre-calculating the linear offsets for the given neighborhood (i.e. the non-zeros of the filter), then use that information directly, rather than testing the entire neighborhood for every pixel. |
|
@vakopian We do not have any translations like that as of now. If you can send in a PR for such a contribution, we could consider generalizing it for other window operations. Can you perhaps create a new issue to discuss this further? |
[skip arrayfire ci]