Polygon source, stencil, histogram statistics connected looks good. The code snippet is incomplete (we don’t know the image geometry, we don’t know how the reslice filter is set up), so we could only guess what’s wrong.
It can help you if you view the output of each filter in an image viewer. For prototyping and getting to know VTK, I would recommend using Python instead of C++, with PyVista (to visualize with scripting) or 3D Slicer (to visualize with an interactive GUI).