forked from hieulem/whale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_trainingpatches.py
executable file
·33 lines (30 loc) · 950 Bytes
/
gen_trainingpatches.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
import numpy as np
from PIL import Image
import time
import torch
import os.path
import argparse
from scipy import misc
from m_util import *
parse = argparse.ArgumentParser()
parse.add_argument('--root',type=str,default='./Water_Training')
parse.add_argument('--step',type=int,default=500)
parse.add_argument('--size',type=int,default=30)
parse.add_argument('--output',type=str,default='./water')
opt = parse.parse_args()
opt.im_fold = opt.root
opt.results = opt.output
sdmkdir(opt.results)
opt.input_nc =3
imlist=[]
imnamelist=[]
for root,_,fnames in sorted(os.walk(opt.root)):
for fname in fnames:
if fname.endswith('.PNG'):
path = os.path.join(root,fname)
imlist.append((path,fname))
imnamelist.append(fname)
for im_path,imname in imlist:
png = misc.imread(im_path,mode='RGB')
w,h,z = png.shape
savepatch_train(png,w,h,opt.step,opt.size,opt.results+'/'+imname[:-4]+'#')