-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefining_pixels.py
More file actions
58 lines (32 loc) · 1.07 KB
/
defining_pixels.py
File metadata and controls
58 lines (32 loc) · 1.07 KB
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
54
55
#!/usr/bin/env python
'''
Boilder plate for peforming algorithm
'''
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import cKDTree
from PIL import Image, ImageFilter
import csv
# example case 2700
width = 1350
height = int(width/2)
# load raster image and note which points are lit
image = Image.open(f'usa-raster-flat-{str(width)}.png')
pixels = np.array(image)
#load raster image and note which points define the border
border = image.filter(ImageFilter.FIND_EDGES)
border_pixels = np.array(border)
#convert to interger arrays rather then boolean
pixels = pixels*1
border_pixels = border_pixels*1
#sum to defined index values for border, inside and outside.
pixel_indicies = (pixels+border_pixels)
#We now have an 2D numpy array where:
pixel_indicies_alt = pixel_indicies - 1
#Inner pixels: 0, Outer pixels: -1, border_pixels: 1
pixel_indicies = pixel_indicies*(255/2)
print(pixel_indicies)
image = Image.fromarray(pixel_indicies)
image.show()
with open('pixels_file.txt', 'w') as f:
csv.writer(f, delimiter=' ').writerows(pixel_indicies_alt)