-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_patches.py
46 lines (36 loc) · 1.34 KB
/
generate_patches.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
# Script to read dill data objects as numpy arrays.
from PIL import Image
import os
import sys
import logging
root = logging.getLogger()
root.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
from mapdataset import ImageGroupReader, single_layer_converter, MapsDataset, MapReader
sfMap = MapReader('./data/input/sf_layered.txt', "SF_Layered")
mapsDataset = MapsDataset(
patch_size=(32, 32),
stride=10,
sample_group_size=1280,
converter=single_layer_converter,
outputDir="./data/output"
)
mapsDataset.generate_patches(sfMap) #This will generate dill files which contain the saved sample lists.
# dillFolder = "./data/output/SF_Layered/32x32/stride-10"
# nGroups = 0
# # Iterate directory
# for path in os.listdir(dillFolder):
# # check if current path is a file
# if os.path.isfile(os.path.join(dillFolder, path)) and path.endswith(".dill"):
# nGroups += 1
# for i in range(nGroups):
# reader = ImageGroupReader(dillFolder)
# data = reader.load_group(groupNo=i)
# patchImgArray = reader.asImg(data[0])
# im = Image.fromarray(patchImgArray)
# path = os.path.join(dillFolder, f"{i}-0.png")
# im.save(path)