Skip to content Skip to sidebar Skip to footer

Rgb_to_hsv And Backwards Using Python And Numpy

I tried to execute this code here as described in this answer. Bu I can't seem to get away from dividing with zero value. I tried to copy this code from caman Js for transforming

Solution 1:

The error comes from the fact that numpy.where (and numpy.select) computes all its arguments, even if they aren't used in the output. So in your line hsv[...,1] = np.where(maxc==0, 0, dif/maxc), dif / maxc is computed even for elements where maxc == 0, but then only the ones where maxc != 0 are used. This means that your output is fine, but you still get the RuntimeWarning.

If you want to avoid the warning (and make your code a little faster), do something like:

nz = maxc != 0   # find the nonzero values
hsv[nz, 1] = dif[nz] / maxc[nz]

You'll also have to change the numpy.select statement, because it also evaluates all its arguments.

Post a Comment for "Rgb_to_hsv And Backwards Using Python And Numpy"