one possible (and the most probable) explanation is that some labels within the image are disconnected. In that case, it is not possible to find a path from one component to another, and the geodesic distance within the label is set to infinity.
I suggest applying a connected component labeling algorith prior to computation of geodesic diameter. This should solve the problem.
Anotehr option would be to artificially reconnect the disconnected components, but this will highly depend on the nature of images.