Convert mask and flags input to ndarray