-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmask_generate.py
More file actions
47 lines (40 loc) · 1.19 KB
/
mask_generate.py
File metadata and controls
47 lines (40 loc) · 1.19 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
import cv2
import matplotlib.pyplot as plt
# def mask_generate(I,k,grey_area):
# shape1=I.shape[0]//(2**k)
# shape2=I.shape[1]//(2**k)
# for i in range(len(grey_area)):
# row=grey_area[i]//(2**k)
# col=grey_area[i]-row*(2**k)
# if col==0:
# col=2**k
# col-=1
# startr=row*shape1;endr=(row+1)*shape1
# startc=col*shape2;endc=(col+1)*shape2
# I.copy()[startr:endr,startc:endc,:]=0
# return I
import cv2
import matplotlib.pyplot as plt
def mask_generate(I,k,grey_area):
I_copy = I.copy()
shape1=I.shape[0]//(2**k)
shape2=I.shape[1]//(2**k)
for i in range(len(grey_area)):
row=grey_area[i]//(2**k)
col=grey_area[i]-row*(2**k)
if col==0:
col=2**k
col-=1
startr=row*shape1;endr=(row+1)*shape1
startc=col*shape2;endc=(col+1)*shape2
I_copy[startr:endr,startc:endc,:]=0
return I_copy
#%%
k=1 ### 2^(2*k)
grey_area = [1] ###block number
I=cv2.imread('1f8f08ea-b5b3-4f68-94d4-3cc071b7dce8.png') ###path
plt.imshow(I)
plt.show()
I_m=mask_generate(I,k,grey_area)
plt.imshow(I_m)
plt.show()