code: def preserve_channel_dim(func):
      
      @wraps(func)
      def wrapped_function(img, *args, **kwargs):
          shape = img.shape
          result = func(img, *args, **kwargs)
          if len(shape) == 3 and shape[-1] == 1 and len(result.shape) == 2:
              result = np.expand_dims(result, axis=-1)
          return result
  
      return wrapped_function
docs: Preserve dummy channel dim.