-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoLAB.py
118 lines (97 loc) · 3.77 KB
/
toLAB.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# generate augmented images for training
# - input/: images with original palette
# - output/: images with new palette
# - old_palette/: pickled files of original palette
# - new_palette/: pickled files of new palette
import collections
import pathlib
import random
import pickle
from typing import Dict, Tuple, Sequence
import cv2
from skimage.color import rgb2lab, lab2rgb
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from tqdm import tqdm
import torch
from torch import nn
import torch.nn.functional as F
from torchvision import transforms
from torch.autograd import Variable
device = "cuda" if torch.cuda.is_available() else "cpu"
import cv2
import matplotlib
import os
# def augment_image(img, title, hue_shift):
# #plt.imshow(img)
# #plt.title(f"Original {title} (in RGB)")
# #plt.show()
# img_HSV = matplotlib.colors.rgb_to_hsv(img)
# a_2d_index = np.array([[1,0,0] for _ in range(img_HSV.shape[1])]).astype('bool')
# img_HSV[:, a_2d_index] = (img_HSV[:, a_2d_index] + hue_shift) % 1
# new_img = matplotlib.colors.hsv_to_rgb(img_HSV).astype(int)
# #plt.imshow(new_img)
# #plt.title(f"New {title} (in RGB)")
# #plt.show()
# img = img.astype(np.float) / 255.0
# new_img = new_img.astype(np.float) / 255.0
# ori_img_LAB = rgb2lab(img)#from skimage.color import rgb2lab, lab2rgb
# new_img_LAB = rgb2lab(new_img)
# new_img_LAB[:, :, 0] = ori_img_LAB[:, :, 0]
# new_img_augmented = (lab2rgb(new_img_LAB)*255.0).astype(int)
# plt.imshow(new_img_augmented)
# plt.title(f"New {title} (in RGB) with Fixed Luminance")
# plt.show()
# plt.close()
# return new_img_augmented
# import os
# import pathlib
# for i in range(0,22):
# pathlist=[]
# pathlist = pathlib.Path("data/unlabeled_data/origin_palette/"+str(i)).glob("*.pkl")
# count=0
# for j, path in enumerate(pathlist):
# count=count+1
# print(count)
# print("target")
# for i in range(0,22):
# pathlist=[]
# pathlist = pathlib.Path("data/unlabeled_data/target_palette/"+str(i)).glob("*.pkl")
# count=0
# for j, path in enumerate(pathlist):
# count=count+1
# print(count)
# #pathlist = pathlib.Path("/datasets/dribbble_half/dribbble_half/data").glob("*.png")
# for i in range(0,22):
# pathlist =[]
# pathlist = pathlib.Path("data/unlabeled_data/train/"+str(i)).glob("*.jpg")
# isExists = os.path.exists("data/unlabeled_data/presudo_target/"+str(i))
# if not isExists:
# os.makedirs("data/unlabeled_data/presudo_target/"+str(i))
# for j, path in enumerate(pathlist):
# print(path)
# img = cv2.imread(str(path))
# #im = Image.open(path) # Replace with your image name here
# #indexed = np.array(im) # Convert to NumPy array to easier access
# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# hue_shift = random.random()
# augmented_image = augment_image(img, "Image", hue_shift)
# #cv2.imwrite(f'train/input/{str(i)}/{path.name}', img)
# cv2.imwrite(f'data/unlabeled_data/presudo_target/{str(i)}/{path.name}', augmented_image)
# for i, path in enumerate(pathlist):
# print(i)
# print(path)
# img = cv2.imread(str(path))
# #im = Image.open(path) # Replace with your image name here
# #indexed = np.array(im) # Convert to NumPy array to easier access
# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# hue_shift = random.random()
# augmented_image = augment_image(img, "Image", hue_shift)
# cv2.imwrite(f'train/input/{path.name}', img)
# cv2.imwrite(f'train/output/{path.name}', augmented_image)
for i in range(0,22):
pathlist =[]
isExists = os.path.exists("data/unlabeled_data/val/"+str(i))
if not isExists:
os.makedirs("data/unlabeled_data/val/"+str(i))