Repository navigation
[New feature] Add TV-L1 optical flow algorithm - #3983
Conversation
…into Add_tvl1_optical_flow_method
…into Add_tvl1_optical_flow_method
|
Hello @rfezzani! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2019-09-11 07:09:51 UTC |
|
@rfezzani thanks for this contribution! I apologise that I don't have time to do a proper review right now, but one concern I have is that we are aiming to be a fully n-dimensional library, minimising the amount of 2D-only code as much as possible. From what I can tell, this algorithm generalises quite readily to n-dimensions. Do you think that would be something you would be comfortable doing? Otherwise we can certainly take over at this point! |
|
@jni do we really want to "ndify" the whole library at the start of every contribution? This seems quite intense and I feel like it make make the higher dimension stuff rushed. |
yes. Anything else is taking on debt that we generally can't afford to pay back. I put merging a non-nD request (except where the feature is intrinsically 2D) on almost the same level as merging something without tests with the idea that we'll add them later. The truth is that none of us have time for that. A large proportion of my work on the library for the past 6 years has been patching 2D-only stuff to support nD. This is not to say that the contributor needs to do it, which is why I offered to take over. But I think the 2D tests should be passing before I do. (Again, no time for a full review right now, but if no one else comes in before then, I can help after the SciPy conference.) |
|
While I am also firmly in the belief that n-D is the right path forward, it does result in us not having nice things, or getting them significantly late at times. As just one example, I had perfectly functional and performant 2D code for flood filling in 2015 - simple Cython, still have the gist published - but we wanted it n-D. Flood fill itself didn't get merged until 3 years later. There's a lot we could have done with a 2D or 2D/3D version in the meantime. I'm mostly playing the Devil's Advocate here, but food for thought. |
|
@JDWarner 👋 and looking forward to seeing you next week! =) =) =) The flip side of that coin is that we have nD flood fill now, which I believe might not be true if we'd had 2D already. Not only that, but I think the code ended up much neater in the end. In the current stage of scikit-image's development, I think long-term maintainability is a much greater concern than short term development speed, and that balance is only going to become more lopsided. 2D implementations can live in branches, gists, and WIP PRs and still be useful to the community while nD support is worked out... |
|
Hi all and thanks for your feedback. |
|
Is there a just middle we can hit? Where we ensure the API is compatible with ND, but not actually implement it until followup PRs? I think the most valuable aspect is being able to contribute a small useful chunk at the same time. That ensures that we don't loose interest from the many parties involved in a contribution. The desire to go to ND has for example made it difficult to move the color module over because it is hard to ensure backward compatibility with the majic that was decided long ago. For example, I was able to do something like this in numpy where I was able to improve the np.block algorithm without having to write it in C. For a certain usecase, it was actually slower than the naive implementation. It was decided that python workarounds (falling back on the previous implementation) were allowed and that the C Port could be delayed until further notice. |
This might be possible. Already this PR doesn't meet that bar (at first glance) because it uses warp, which uses reversed coordinates, again, partly because warp assumed 2D images when it was written long ago.
For me this makes the complete opposite point: moving forward has been extremely difficult because of code that assumed 2D inputs. There's many examples like this.
This is definitely a huge concern, and thanks for keeping it in focus! But it is one among several. My proposed solution to "fast contribution experiences" is that maintainers should help contributors by pushing commits to the PR branch, not that we lower our standards for long-term maintainability. @rfezzani sorry that the discussion has gone off track a little bit. I just saw that your tests are passing, so at this point you can take a break. =) Thanks for your contribution! We'll do some review, maybe argue a little bit =P, and then help push it to nD, but again, from me at least this has to happen after SciPy. |
from skimage.transform import warp
import numpy as np
img = np.random.randn(256, 256, 256)
I, J, K = np.meshgrid(np.arange(256), np.arange(256), np.arange(256))
img = warp(img, np.array([I, J, K]))I may be don't understood what you mean, but even if
Don't worry @jni, this discussion is a big concern: is the nD support a condition for the inclusion of a new feature in skimage? In my opinion, this is a huge requirement, difficult to reach in many cases. By the way, listing all the actual skimage functions only supporting 2D and creating the corresponding issues for extending their support to nD can be interesting. What do you think? |
|
Hi everyone, |
|
Thank you both, @jni and @alexdesiqueira, for your review and comments. The code looks much better now. |
| assert np.all(flow == 0) | ||
|
|
||
|
|
||
| def test_no_motion_3d(): |
There was a problem hiding this comment.
Great! This will at least exercise the code. =)
Another test would be to use ndimage transforms that are expected to produce a particular pattern of flow. For example, wouldn't shrinking the image about its center produce a radially shrinking field with predictable flow? Or, more simply, a translation of x, y, z pixels should produce that flow uniformly across the image, right?
There was a problem hiding this comment.
Yes, good suggestion, but the resulting optical flow will not be equal to the ground truth, all we can do is expect a result reasonably close to the true solution. I will give this a try ASAP ;-)
jni
left a comment
There was a problem hiding this comment.
I'm into it! 😂 I've made a minor and optional suggestion for a new test, but it can come later I think. I'll let someone else look it over for completeness.
…into Add_tvl1_optical_flow_method
…into Add_tvl1_optical_flow_method
|
Hi @jni, I finally managed to add non trivial tests for the optical flow estimation. Is it OK for you? |
jni
left a comment
There was a problem hiding this comment.
@rfezzani this is just fantastic right now! I've left some very minor comments that should be addressed before merging, but otherwise I'm amazed where you've got this to. 👏 👏 👏 The new test is 👌 perfect.
I still would rename the main function just "optical_flow", but I definitely understand the arguments for not doing so.
Other than the changes proposed, it's up to @alexdesiqueira to merge! =)
|
Thank you again @jni for your review, this PR is much better now then its first implementation ;-). |
|
Hey @rfezzani, I really think this could have better name variables, once I read it and don't understand that much yet. However, how I liked the algorithm! This seems a lot useful (and I'm seeing applications for that right now). But @jni pointed several points and you dealed with them all, therefore I won't hold it. |
|
Hi @alexdesiqueira, thank you again for your review. I am really happy if this new feature can help you! I am sorry if you feel that variable names can be more explicit, this may be addressed in a documentation improvement issue? Let me know if you have any idea ;-) |
|
Hey @rfezzani, |
Description
As I previously proposed on the mailing list (sorry for the delay), this PR is about the implementation of the TV-L1 algorithm for the estimation of optical flow [1].
I integrated it in the sub-package
skimage.registrationbecause I did not found a better place for it. I hope that there is no conflict with the Meta issue #3810.Concerning the tests, I actually implemented only the zero motion case. I also can implement a non regression test by saving the output of the algorithm in the
datasub-package.For the examples, I used the
stereo_motorcyclesequence that is already included in skimage, but I can also add any of the train sequences from the middlebury dataset : I already asked the maintainer of the project if there is any copyright restriction concerning the distribution of the Middlebury dataset, and there is not.[1]: Zach, C., Pock, T., & Bischof, H. (2007, September). A duality based approach for realtime TV-L 1 optical flow. In Joint pattern recognition symposium (pp. 214-223). Springer, Berlin, Heidelberg.
Checklist
./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x