How to convert images color space in Keras?

前端 未结 2 573

I am feeding RGB color images to a Neural Network implemented with Keras. How can I have Keras convert the images to a different color space (e.g. YUV, Lab, or some grayscal

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-20 21:44

    If you import tensorflow, you can use the tf.image.rgb_to_hsv() function in the lambda:

    def hsv_conversion(x):
        import tensorflow as tf    
        return tf.image.rgb_to_hsv(x)
    
    model.add(Lambda(hsv_conversion, input_shape=(160, 320, 3)))
    

提交回复
热议问题