Home > Mobile >  replacing pixel value of one channel based on values of other two channels
replacing pixel value of one channel based on values of other two channels

Time:09-17

target_positive_replace = np.where(positive_replace[...,0]>0 or positive_replace[...,1]>0 or positive_replace[...,2]>0),target_positive_replace[...,1]=255 ,0)

I have a three-channel RGB image.

Want to perform above operation.

if one of the given values in a channel is greater than zero (channel value>0). I want to make that pixel green. (0,255,0).

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

CodePudding user response:

Your problem is that positive_replace[...,x] returns an array which cannot be checked with >0(wrong). So as the Error Message states you can either check each element of the returned array with a.all() or a.any() or you have to make sure to retreive the integer color value.

Edit

The above is only partially true. As @Cris Luengo states in his comment or expects a single value, not an array. So either compare single values with a.all() and a.any() or compare the boolean array returned by positive_replace[...,x]>0 with |

  • Related