-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast_detection.py
More file actions
31 lines (19 loc) · 875 Bytes
/
Copy pathfast_detection.py
File metadata and controls
31 lines (19 loc) · 875 Bytes
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
from PIL import Image
import numpy as np
#PIl has a max_iamge pixels size of 80kk, and tif image are usaly bigger
Image.MAX_IMAGE_PIXELS = 130000000
image_name = 'test_river.tif'
im = Image.open(image_name)
image_np_arr = np.array(im)
for i in range(image_np_arr.shape[0]):
for j in range(image_np_arr.shape[1]):
if image_np_arr[i,j,0] <= 0 and image_np_arr[i,j,1] <= 0 and image_np_arr[i,j,2] <= 0:
image_np_arr[i,j] = [0, 0, 0]
else:
image_np_arr[i,j] = [255, 255, 255]
im = Image.new('RGB', (image_np_arr.shape[0], image_np_arr.shape[1]))
for i in range(image_np_arr.shape[0]):
for j in range(image_np_arr.shape[1]):
im.putpixel((i,j), (image_np_arr[i,j,0], image_np_arr[i,j,1], image_np_arr[i,j,2]))
im = (im.transpose(Image.ROTATE_90)).transpose(Image.FLIP_TOP_BOTTOM)
im.save("result_test_algo.jpg")