-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatch_creation.py
54 lines (30 loc) · 1.43 KB
/
Patch_creation.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
52
53
54
import os
import Image
for file in os.listdir(dir_data):
outfile=os.path.splitext(file)[0]
extension=os.path.splitext(file)[1]
if (extension==".tif"):
continue
im = Image.open(os.path.join(dir_mask+outfile+"_EX"+".tif")).convert('RGB')
imd = Image.open(os.path.join(dir_data,file)).convert('RGB')
patch_id = 0
for i in range(10):
for j in range(16):
top_y = i*256
if (i==9):
top_y = 2336
top_x = j*256
if (j==15):
top_x = 3776
im_crop = im.crop((top_x,top_y,top_x+512,top_y+512))
imd_crop = imd.crop((top_x,top_y,top_x+512,top_y+512))
im_crop = np.array(im_crop)
if np.sum(im_crop)==0: # for calculating the number of total black patches.
negative_patches.append(output_dir_mask+outfile+"_p"+str(patch_id)+extension)
else :
positive_count+=1
# im_crop = (im_crop > 50) * 1.0
im_crop=PIL.Image.fromarray(im_crop)
im_crop.save(output_dir_mask+outfile+"_p"+str(patch_id)+extension)
imd_crop.save(output_dir_data+outfile+"_p"+str(patch_id)+extension)
patch_id+=1