Hi everyone,
I know this is a bit of a big ask, but I would like to ask the Rust experts to take a look at a fairly small program I have created, and tell me what it is I am doing incorrectly. The program in question can be found at this GitHub repo, where there is the Rust version but also a F# version that I wrote earlier. The version in the branch of the repo linked to above is a bit different now to what I am trying to achieve at first with the Rust version (I started again with the basic implementation), but you can see an F# version of it here.
The program in question is (so far) supposed to be performing basic Belief Propagation stereo matching (it's a Computer Vision thing, for those not in the know), based heavily on the paper "Efficient Belief Propagation for Early Vision", by Felzenszwalb & Huttenlocher, published in 2006. My F# version works kinda OK, and for my typical sample input images (attached at the end of this post), it produces a result along the lines of the below:
The problem is that my Rust version, by comparison, appears simply to produce an image of vertical stripes:
The two are run with identical inputs and parameters. I am running the Rust (on Rust 1.36) version with the following command:
cargo run --release -- -l "..\Images\Input\tsukuba-imL.png" -r "..\Images\Input\tsukuba-imR.png" -o "..\Images\Output\" -a bp -d 16 -n 10
And the F# version (on .NET Core 2.2) :
dotnet run -c Release -l "..\Images\Input\tsukuba-imL.png" -r "..\Images\Input\tsukuba-imR.png" -o "..\Images\Output\" -d=16 -n=10 -a beliefpropagation
Changing the number of iterations (controlled by the 'n' parameter) makes the differences between the light and dark stripes more prominent, but otherwise appears to have no impact. I have been over every line of my program twice trying to work out what I am doing wrong. So far as I can see, everything in my Rust program pretty much exactly duplicates my F# program - certainly none of the minor differences would appear to explain the issue.
I had thought that the problem might one of these two:
-
I instantiate a triply-nested vec (i.e. Vec<Vec<Vec>>) using a map over a range, inside which I use nested vec! macros. I figured that maybe that in fact was simply inserting a whole bunch of references/pointers to the exact same vec somewhere in the stack.
-
I make a copy of the vec mentioned above by using .clone() on it. Perhaps that was simply making a second pointer to the same vec, rather than actually making an identical new copy.
The problem is, I have already tried out alternatives for both of those issues, and it seems to have had precisely no effect. At this point, I am absolutely stumped as to what the problem could be, but I'm forced to conclude that there's probably something I just don't understand about how Rust (or maybe one of the crates) works that is tripping me up. Unfortunately, I haven't been able to glean any insights from what I have been able to find online. Or maybe just I'm missing something really small that my tired eyes cannot spot
If anyone is interested, could you please take a look in the repository linked above and see if you can spot any potential issues. Please also let me know if I should add any more information to this post. Also, please feel free to critique any other aspect of my program - no doubt it is not presently optimal. In fact, it runs substantially slower than I would expect, to be honest.
Thank you in advance