pr下雪下雨
by Ujjwal Saxena
由Ujjwal Saxena
图像增强:下雨,下雪。 如何修改照片以训练自动驾驶汽车 (Image Augmentation: Make it rain, make it snow. How to modify photos to train self-driving cars)
Image Augmentation is a technique for taking an image and using it to generating new ones. It’s useful for doing things like training a self-driving car.
图像增强是一种获取图像并将其用于生成新图像的技术。 这对于进行自动驾驶汽车的训练非常有用。
Think of a person driving a car on a sunny day. If it starts raining, they may initially find it difficult to drive in rain. But slowly they get accustomed to it.
想想一个人在晴朗的一天开车。 如果开始下雨,他们最初可能会发现下雨时很难开车。 但是他们逐渐习惯了。
An artificial neural network too finds it confusing to drive in a new environment unless it has seen it earlier. Their are various augmentation techniques like flipping, translating, adding noise, or changing color channel.
人工神经网络也发现在新环境中驾驶时会感到困惑,除非早先见过。 它们是各种增强技术,例如翻转,平移,添加噪声或更改颜色通道。
In this article, I’ll explore the weather part of this. I used the OpenCV library for processing images. I found it pretty easy after a while, and was able to introduce various weather scenarios into an image.
在本文中,我将探讨天气的一部分。 我使用OpenCV库处理图像。 一段时间后,我发现这很容易,并且能够将各种天气情况引入图像中。
I’ve pushed a fully implemented Jupyter Notebook you can play with on GitHub.
我推了一个完全实现的Jupyter Notebook,您可以在GitHub上使用它 。
Lets’ have a look.
我们来看一下。
I’ll first show you an original test image and will then augment it.
首先,我将向您展示原始测试图像,然后对其进行放大。
阳光明媚和阴暗 (Sunny and Shady)
After adding random sunny and shady effect, the image’s brightness changes. This is an easy and quick transformation to perform.
添加随机的晴天和阴暗效果后,图像的亮度会改变。 这是一个容易快速执行的转换。
def add_brightness(image): image_HLS = cv2.cvtColor(image,cv2.COLOR_RGB2HLS) ## Conversion to HLS image_HLS = np.array(image_HLS, dtype = np.float64) random_brightness_coefficient = np.random.uniform()+0.5 ## generates value between 0.5 and 1.5 image_HLS[:,:,1] = image_HLS[:,:,1]*random_brightness_coefficient ## scale pixel values up or down for channel 1(Lightness) image_HLS[:,:,1][image_HLS[:,:,1]>255] = 255 ##Sets all values above 255 to 255 image_HLS = np.array(image_HLS, dtype = np.uint8) image_RGB = cv2.cvtColor(image_HLS,cv2.COLOR_HLS2RGB) ## Conversion to RGB return image_RGB
The brightness of an image can be changed by changing the pixel values of “Light