forked from hwiyoung/Orthophoto_Maps_Multispectral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoundary.py
51 lines (34 loc) · 1.38 KB
/
Boundary.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
import numpy as np
def boundary(image, eo, R, dem, pixel_size, focal_length):
inverse_R = R.transpose()
image_vertex = getVertices(image, pixel_size, focal_length) # shape: 3 x 4
proj_coordinates = projection(image_vertex, eo, inverse_R, dem)
bbox = np.empty(shape=(4, 1))
bbox[0] = min(proj_coordinates[0, :]) # X min
bbox[1] = max(proj_coordinates[0, :]) # X max
bbox[2] = min(proj_coordinates[1, :]) # Y min
bbox[3] = max(proj_coordinates[1, :]) # Y max
return bbox
def getVertices(image, pixel_size, focal_length):
rows = image.shape[0]
cols = image.shape[1]
# (1) ------------ (2)
# | image |
# | |
# (4) ------------ (3)
vertices = np.empty(shape=(3, 4))
vertices[0, 0] = -cols * pixel_size / 2
vertices[1, 0] = rows * pixel_size / 2
vertices[0, 1] = cols * pixel_size / 2
vertices[1, 1] = rows * pixel_size / 2
vertices[0, 2] = cols * pixel_size / 2
vertices[1, 2] = -rows * pixel_size / 2
vertices[0, 3] = -cols * pixel_size / 2
vertices[1, 3] = -rows * pixel_size / 2
vertices[2, :] = -focal_length
return vertices
def projection(vertices, eo, rotation_matrix, dem):
coord_GCS = np.dot(rotation_matrix, vertices)
scale = (dem - eo[2]) / coord_GCS[2]
plane_coord_GCS = scale * coord_GCS[0:2] + [[eo[0]], [eo[1]]]
return plane_coord_GCS