Reputation: 69
I got some if/elif structures. I have no errors when it runs, but the 3 outputs are the same (they should not be). I can not really see, what is the cause of this problem.
The concerned part of my code: (RGB_l is a 1 by 3 matrix, I create a variable for each of its component and apply an if/elif structure, to decide which calculation needs to be done).
X = float(input("X: "))/100
Y = float(input("Y: "))/100
Z = float(input("Z: "))/100
b = np.array([[X],
[Y],
[Z]])
a = np.array([[3.2406, -1.5372, -0.4986],
[-0.9689, 1.8758, 0.0415],
[0.0557, -0.2040, 1.057]])
RGB_l = np.dot(a, b)
print("RGB linear :", RGB_l)
R_l = RGB_l[0, 0]
G_l = RGB_l[1, 0]
B_l = RGB_l[2, 0]
a = 0.055
if R_l <= 0.0031308:
R = 12.92*R_l
elif R_l > 0.0031308:
R = ((1+a)**(1/2.4))-a
print(R)
if G_l <= 0.0031308:
G = 12.92*G_l
elif G_l > 0.0031308:
G = ((1+a)**(1/2.4))-a
print(G)
if B_l <= 0.0031308:
B = 12.92*B_l
elif B_l > 0.0031308:
B = ((1+a)**(1/2.4))-a
print(B)
Outputs for R, G and B are :
0.967559351663262
0.967559351663262
0.967559351663262
Could you help me to fix my code? Thanks
Upvotes: 0
Views: 45
Reputation: 861
All the values you have are greater than 0.0031308
and so the print statement for each is ((1+a)**(1/2.4))-a
the actual value in the array isn't part of the output.
Upvotes: 1