-
Notifications
You must be signed in to change notification settings - Fork 92
/
image_helper.py
34 lines (24 loc) · 945 Bytes
/
image_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''
image_helper.py : contains loadgray() method to load an RGBA image in PNG format
and return a grayscale image
Copyright (C) 2017 Jack Baird, Alex Cantrell, Keith Denning, Rajwol Joshi,
Simon D. Levy, Will McMurtry, Jacob Rosen
This file is part of AirSimTensorFlow
MIT License
'''
import matplotlib.pyplot as plt
# Images are too big to train quickly, so we scale 'em down
SCALEDOWN = 6
# Where we'll store images
IMAGEDIR = './carpix'
# Create images directory if it doesn't exist
def loadgray(filename):
'''
Loads an RGBA image from FILENAME, converts it to grayscale, and returns a flattened copy
'''
image = plt.imread(filename)
# RGB -> gray formula from https://www.johndcook.com/blog/2009/08/24/algorithms-convert-color-grayscale/
image = 0.21 * image[:,:,0] + 0.72 * image[:,:,1] + 0.07 * image[:,:,2]
image = image[0::SCALEDOWN, 0::SCALEDOWN]
image = image.flatten()
return image