Repository navigation
Expand file tree
/
Copy pathimage_test.py
More file actions
53 lines (37 loc) · 1.44 KB
/
Copy pathimage_test.py
File metadata and controls
53 lines (37 loc) · 1.44 KB
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
import numpy as np
from PIL import Image
import glob
batch_size = 32
train_folder = "dataset/io/*"
images = [Image.open(file).convert("LAB") for file in glob.glob(train_folder)]
image = np.asarray(images[0])
print(image.shape)
mask = np.zeros((image.shape[0], image.shape[1]), dtype=np.float32)
num_points = 100000#np.random.randint(1,15000)
total_points = image.shape[0] * image.shape[1]
random_points = np.random.choice(total_points, size = num_points, replace=False)
for index in random_points:
row, col = divmod(index, image.shape[1])
mask[row, col] = 1
# Create a masked image
hints = image.copy()
# Apply the mask to all three channels of the LAB image
#for i in range(3):
hints[:, :, 0] = image[:, :, 0] * mask /100.0# h,w,c
hints[:, :, 1] = image[:, :, 1] * mask /255.0# h,w,c
hints[:, :, 2] = image[:, :, 2] * mask /255.0# h,w,c
# Convert back to RGB for display
l_hints = Image.fromarray(hints[:, :, 0].astype('uint8'))#.convert('RGB')
alpha_hints = Image.fromarray(hints[:, :, 1].astype('uint8'))#.convert('RGB')
beta_hints = Image.fromarray(hints[:, :, 2].astype('uint8'))
image_rgb = Image.fromarray(image.astype('uint8'), 'LAB')#.convert('RGB')
print(f"Alpha Mean: {np.mean(alpha_hints)}")
print(f"Alpha Min: {np.min(alpha_hints)}")
print(f"Alpha Max: {np.max(alpha_hints)}")
print(f"Alpha Std: {np.std(alpha_hints)}")
# Show the masked image
#masked_image_rgb.show()
l_hints.show()
alpha_hints.show()
beta_hints.show()
image_rgb.show()