File size: 1,086 Bytes
5db43ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
def crop(img: np.ndarray, up=0.2, down=0.02, left=0.0, right=0.0):
    new_img=img.copy()
    height, width = new_img.shape[:2]
    n_row = int(height * up)
    n_left = int(width * left)
    n_right = int(width * right)
    n_down = int(height * down)
    new_img=new_img[n_row:height-n_down,n_left:width-n_right:,:]
    return new_img

def crop_16_9(img: np.ndarray, up=0.2, left=0.0, right=0.0):
    new_img=img.copy()
    height, width = new_img.shape[:2]
    n_row = int(height * up)
    n_left = int(width * left)
    n_right = int(width * right)
    n_down = int(height - (width - n_right - n_left)*16/9 -n_row)
    new_img=new_img[n_row:height-n_down,n_left:width-n_right:,:]
    return new_img

def crop_4_3(img: np.ndarray, up=0.2, left=0.0, right=0.0):
    new_img=img.copy()
    height, width = new_img.shape[:2]
    n_row = int(height * up)
    n_left = int(width * left)
    n_right = int(width * right)
    n_down = int(height - (width - n_right - n_left)*4/3 -n_row)
    new_img=new_img[n_row:height-n_down,n_left:width-n_right:,:]
    return new_img