Why does my program just produce an image of vertical stripes?

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 :man_shrugging:t2:

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 :slight_smile:

tsukuba-imL tsukuba-imR

it looks like the following code ignores the y coordinate of the pixel:



You are entirely correct, that was the issue. Thank you very much! :+1:t2: I suspect it would have taken me a looong time to spot that (I had literally spent the last couple of days trying to work out where the problem was...) Having fixed that, I now get the below, roughly correct, result:

If anybody still wants to take a look at the code and give suggestions, please do feel free :slight_smile:


One good thing about rust is that you're not going to accidentally do any of these. If you have several references to the same thing, the compiler will force you to go through a whole bunch of hoops if you want to do any modifications to it.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.