Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ERROR- if r < (75,0,0) and g < (0,75,0) and b < (0,0,255) and b > (0,0,128) : ValueError: operands could not be broadcast together with shapes (558,800) (3,)


import cv2
import numpy as np
from PIL import Image

#image=Image.open('flower.png')
image=cv2.imread("flower.png")
arr=np.array(image)
#arr[:,:]=[,,0]
print(arr[10,10,:])
print(arr.shape)
print(arr.dtype)
print(arr.size)
print(arr.ndim)
print(arr)
r =image[:,:,0]
g =image[:,:,1]
b =image[:,:,2]
print(r,g,b)

'''Rmask= np.all(image==b,axis=-1)
image[Rmask]=[255,255,255]'''

if r  < (75,0,0) and g  < (0,75,0) and b < (0,0,255) and b > (0,0,128) :
       r=(255, 255, 255) 
       g=(255, 255, 255)
       b=(255, 255, 255)

image.show()

# assign blue channel to zeros
#arr[:,:,2] = np.zeros([arr.shape[0], arr.shape[1]])


#img=Image.fromarray(arr)
#img.save('flowerr.png')
#img.show()


What I have tried:

How to solve this ?
ERROR- if r < (75,0,0) and g < (0,75,0) and b < (0,0,255) and b > (0,0,128) : ValueError: operands could not be broadcast together with shapes (558,800) (3,)
Posted
Updated 22-Aug-22 1:18am

1 solution

Your values for r, g and b are not matching tuples as shown in the error message.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900