transforms.py 434 B

123456789101112
  1. from fastai.transforms import Transform, TfmType
  2. import cv2
  3. class BlackAndWhiteTransform(Transform):
  4. def __init__(self, tfm_y=TfmType.NO):
  5. # Blur strength must be an odd number, because it is used as a kernel size.
  6. super().__init__(tfm_y)
  7. def do_transform(self, x, is_y):
  8. x = cv2.cvtColor(x, cv2.COLOR_BGR2GRAY)
  9. x = cv2.cvtColor(x,cv2.COLOR_GRAY2RGB)#Gets the 3 channels back
  10. return x