I don’t think you would necessarily need to transform the inputs first to PIL.Images, as the method seems to return numpy arrays.
Since you are already passing numpy arrays to this method, you would need to check the channel dimension (instead of the mode) and re-write the logic to work on numpy arrays directly.