-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_solver.py
More file actions
77 lines (59 loc) · 2.26 KB
/
Copy pathnew_solver.py
File metadata and controls
77 lines (59 loc) · 2.26 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Script for finding the deactivation times and real colors of an image
Note: deactivation_dictionary.txt and fullImage.png must both exist in this folder for this code to work
--> deactivation_dictionary.txt can be generated by deactivation_time_generate.py
--> fullImage.png can be generated by ChromoLCD_GUI by saving an image in the UI
"""
# Echo server program
# import socket
import numpy as np
from PIL import Image
from scipy.optimize import lsq_linear
import time as pytime
import json
# FULL_DEACTIVATION_TIME = (
# (1000.0, 1950.0, 40000.0),
# (1800.0, 600.0, 650.0),
# (2400.0, 1000.0, 35.0)
# ) # Photochromeleon
# row 1: cyan; row 2: magenta; row 3: yellow
# col 1: red; col 2: green ; col 3: blue
FULL_DEACTIVATION_TIME = [[467, 712, 687], [1500, 242, 177], [10000, 900, 20]]
# these seem to be more accurate times than the version below
# version 1:
# inf= 1000000
# FULL_DEACTIVATION_TIME = [[3500,2000,3600],[2000,2000,1000],[inf,4500,60]]
RGB_SCALE = 255
CMYK_SCALE = 1
def myround(x, base=5):
return base * round(x/base)
start = pytime.time()
image = Image.open('fullImage.png') # Filename
imagearr = np.asarray(image.convert("RGB"))
#redImage, greenImage, blueImage = image.split() # Saves the redscale, greenscale, and bluescale versions of images
# Note: Dictionary is current sorted as follows:
# "(R, G, B)": [time, realColor]
with open("deactivation_dictionary.txt", "r") as file:
deactivation_dictionary = json.load(file)
newimg = np.empty(imagearr.shape)
times = np.empty(imagearr.shape)
height, width, _ = imagearr.shape
print(f"{height}x{width} image")
for i in range(height):
for j in range(width):
red = myround(imagearr[i][j][0])
green = myround(imagearr[i][j][1])
blue = myround(imagearr[i][j][2])
RGBString = str((red, green, blue))
values = deactivation_dictionary[RGBString]
times[i][j] = values[0] # Values[0] is a list of 3 time values
newimg[i][j] = values[1] # Values[1] is a list of the RGB real color values
def clip_int(arr):
return np.clip(arr.astype(np.uint8), 0, 255)
def savergb(arr, name):
Image.fromarray(clip_int(arr)).save(name)
savergb(newimg, f"fullImage_real.png")
# savergb(times, f"times.png")
end = pytime.time()
print(end - start)
#print(times)