def hsv_to_rgb(R,G,B):
def get_H():
if B < G:
return get_c()
else:
return 360 - get_c()
def get_S():
if R+G+B == 0:
return "undef"
return 1-(3/(R+G+B))*min(R, G, B)
def get_I():
return (R+G+B)/3
def get_c():
return math.acos((2*R-G-B)/(2*math.sqrt((R-G)**2+(R-B)*(G-B))))
return get_H(), get_S(), get_I()
# Ejemplo
values = [(100, 0, 0), (0, 60, 0), (0, 0, 240), (122, 121, 122), (2, 243, 4)]
for pair in values:
R, G, B = pair
print("\n---------")
print("R: {} | G: {} | B: {}".format(R, G, B))
H, S, I = hsv_to_rgb(R, G, B)
print("\n---------")
print("H: {0:.4f}".format(H))
print("S: {0:.4f}".format(S))
print("I: {0:.4f}".format(I))
print("---------\n")
def my_rgb2cmy(im):
CMY = 255-im
return CMY
def my_cmy2rgb(im):
RGB = 255-im
return RGB
Im = Image.open('build.jpg')
Im_a = np.array(Im)
plt.figure()
plt.imshow(Im_a)
plt.title('IMAGEN ORIGINAL')
plt.axis("off")
Im_cmy = my_cmy2rgb(Im_a)
plt.figure()
plt.imshow(Im_cmy)
plt.title('IMAGEN CMY')
plt.axis("off")
Im_hsi = hsv_to_rgb(Im_cmy)
plt.figure()
plt.imshow(Im_hsi)
plt.title('IMAGEN HSI')
plt.axis("off")
The code only lacks the part in which it converts an image to HSV (HSI) but I still have this error:
Im_hsi = hsv_to_rgb(Im_cmy)
TypeError: hsv_to_rgb() missing 2 required positional arguments: 'G' and 'B'
I know I have to input the RGB channels so that I receive the parameter, but I have not managed to get it done.
if I do
R: im[:,:0]
G: im[:,:1]
B: im[:,:2]
I get an error.
I need help with this!