Skip to content

Commit 2b8a548

Browse files
committed
feat: add utils combine_tocenter for combining two image
1 parent d77a295 commit 2b8a548

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

utils.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def combine_tocenter(src_image, dst_image):
2+
''' Combine two image to be one single image '''
3+
# get shape
4+
bh, bw, _ = dst_image.shape
5+
sh, sw, _ = src_image.shape
6+
7+
# get center
8+
lh = int((bh - sh) / 2 )
9+
lw = int((bw - sw) / 2)
10+
rh = bh - lh
11+
rw = bw - lw
12+
13+
#normalize dimension error if dimension is not match
14+
new_img = dst_image
15+
nh, nw, _ = dst_image[lh:rh, lw:rw].shape
16+
17+
#find difference dimension between new shape and replacement image
18+
kh = nh - sh
19+
kw = nw - sw
20+
21+
#normalize dimension dimension
22+
rh = rh - kh
23+
rw = rw - kw
24+
25+
#Replace Image in center
26+
new_img[lh:rh, lw:rw] = src_image
27+
return new_img
28+

0 commit comments

Comments
 (0)