I glanced through the code and I didn’t see anything obvious except the part I was mentioning earlier.
To really go to the bottom of it, I will have to run your code with the proper dataset and I don’t necessarily have the time right now. But if you need dedicated help, you can reach out to Kitware for support hours.