-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread_patches.py
56 lines (44 loc) · 1.6 KB
/
read_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
47
48
49
50
51
52
53
54
55
56
# Script to read dill data objects as numpy arrays.
from PIL import Image
import os
import sys
import logging
from random import randint
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
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, ImageUtils
dillFolder = "./data/output/SF_Layered/32x32/group-1280-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)
mapsDataset = MapsDataset(
patch_size=(32, 32),
stride=10,
sample_group_size=1280,
converter=single_layer_converter,
outputDir="./data/output"
)
mapsDataset.loadPatches("./data/output/SF_Layered/32x32/group-1280-stride-10")
patchNo = randint(0, len(mapsDataset))
logging.info(f"reading patch {patchNo}")
patch = mapsDataset[patchNo]
# im = ImageUtils.PILPatchToPILImg(patch)
# im = ImageUtils.PILPatchToPILImg(patch)
im = ImageUtils.TorchNpPatchToPILImgGray(patch)
path = os.path.join(dillFolder, f"{patchNo}.png")
im.save(path)