-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateRealPatch.py
59 lines (41 loc) · 2 KB
/
generateRealPatch.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
57
58
59
from os import listdir
from os.path import join
import cv2
from tqdm import tqdm
import config
def main() :
# Read Options
opt = config.readArguments(train=True)
# Make Directory Path for Saving Patches
sourcePath = join(opt.dataRoot, "SIDD", "train", "original", "noisy")
targetPath = join(opt.dataRoot, "SIDD", "train", "original", "clean")
# Set Patch Size and Stride
patchSize, stride = 300, 300
# Generate Patch
for imageName in listdir(sourcePath) :
imagePath = join(sourcePath, imageName)
image = cv2.imread(imagePath)
height, width = image.shape[:2]
patchNum = 0
with tqdm(total=(height//stride)*(width//stride)) as pBar :
for i in range(height//stride) :
for j in range(width//stride) :
patch = image[i*stride:i*stride+patchSize, j*stride:j*stride+patchSize, :]
cv2.imwrite(join(opt.dataRoot, "SIDD", "train", "patch", "noisy", imageName.replace(".PNG", f"-{patchNum}.PNG")), patch)
patchNum += 1
pBar.set_description(f"< Noisy Dataset > {imageName}"), pBar.update()
# Generate Patch
for imageName in listdir(targetPath) :
imagePath = join(targetPath, imageName)
image = cv2.imread(imagePath)
height, width = image.shape[:2]
patchNum = 0
with tqdm(total=(height//stride)*(width//stride)) as pBar :
for i in range(height//stride) :
for j in range(width//stride) :
patch = image[i*stride:i*stride+patchSize, j*stride:j*stride+patchSize, :]
cv2.imwrite(join(opt.dataRoot, "SIDD", "train", "patch", "clean", imageName.replace(".PNG", f"-{patchNum}.PNG")), patch)
patchNum += 1
pBar.set_description(f"< Clean Dataset > {imageName}"), pBar.update()
if __name__ == "__main__" :
main()