-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforest_fire.py
53 lines (42 loc) · 1.43 KB
/
forest_fire.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
File: forestfire.py
----------------
This program highlights fires in an image by identifying
pixels who red intensity is more than INTENSITY_THRESHOLD times
the average of the red, green, and blue values at a pixel.
Those "sufficiently red" pixels are then highlighted in the
image and the rest of the image is turned grey, by setting the
pixels red, green, and blue values all to be the same average
value.
"""
# The line below imports SimpleImage for use here
# Its depends on the Pillow package being installed
from simpleimage import SimpleImage
DEFAULT_FILE = 'images/greenland-fire.png'
def find_flames(filename):
"""
This function should highlight the "sufficiently red" pixels
in the image and grayscale all other pixels in the image
in order to highlight areas of wildfires.
"""
image = SimpleImage(filename)
# TODO: your code here
return image
def main():
# Get file and load image
filename = get_file()
image = SimpleImage(filename)
# Show the original fire
original_fire = SimpleImage(filename)
original_fire.show()
# Show the highlighted fire
highlighted_fire = find_flames(filename)
highlighted_fire.show()
def get_file():
# Read image file path from user, or use the default file
filename = input('Enter image file (or press enter): ')
if filename == '':
filename = DEFAULT_FILE
return filename
if __name__ == '__main__':
main()