It's hard to diagnose unseen code, but based on the extreme contrast in the output image, I'd suspect that you're operating at some point on improperly-scaled data (e.g. uint8-scale float instead of unit-scale float). If that's the case, it's not clear whether the output could be fixed by rescaling after the fact, or if it's already suffered truncation at some point.
That's just a guess.