Use a.any () or a.all ()

0

I have this code:

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import FuncionesFiltros as fun

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 = fun.my_cmy2rgb(Im_a)
plt.figure()
plt.imshow(Im_cmy)
plt.title('IMAGEN ORIGINAL A CMY')
plt.axis("off")

Im_rgb = fun.my_rgb2cmy(Im_cmy)
plt.figure()
plt.imshow(Im_rgb)
plt.title('IMAGEN CMY A RGB')
plt.axis("off")


Im_hsi = fun.RGB_TO_HSI(Im_rgb)
plt.figure()
plt.imshow(Im_hsi)
plt.title('IMAGEN RGB A HSI')
plt.axis("off")

And I have this function that imported:

def RGB_TO_HSI(im):
    R=im[:,:,0]
    G=im[:,:,1]
    B=im[:,:,2]
    [row, col,c] = im.shape
    i = np.zeros((row, col))

    for i in range(0, row-1):
        if (0<=R[i]<=255):

            d = R+G+B
            r = float(R)/d
            g = float(G)/d
            b = float(B)/d
            numerador = float( 0.5 * ((r - g) + (r - b)))
            denominador = float(((r - g)**(2) + (r - b)*(g - b))**(0.5))

    if(b <= g):
        h = math.acos(numerador/denominador)

    if(b > g):

        h = (2*math.pi) -  math.acos(numerador/denominador )
        s = 1 - (3/(d)* min(d))
        i = 1 * (d)/3

        H = h*(180/math.pi)
        S = s*100
        I = i*255


        return H, S, I

And I get this error:

    if (0<=R[i]<=255):

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

How could I better implement the conditional?

Thanks

    
asked by Basilio Saldarriaga 04.10.2018 в 22:30
source

0 answers