Simple raw pixel colour changing
I have check already in OpenCV forum, this is not duplicate question.
I want to change a colour in an image, say with [B,G,R]
value [49,51,31]
I used a loop to change pixel with these intensity values to white [255,255,255]
Here's a loop in python
for row in range(r):
for col in range(c):
if np.all(cim[row,col] == [49,51,31]):
cim[row,col] = [255,255,255]
It takes around 30 seconds
for my current test image of resolution [1908,1429]
to complete this.
I came across this post
changing all the Red
values in a colour image < 255
to 255
img[img[:, :, 2] < 255, 2] = 255
using numpy fancy indexing
I tried out same for the above condition of mine
cim1[cim1[:,:]==[49,51,31]] =[255,255,255]
But I'm getting this error
cim1[cim1[:,:]==[49,51,31]] =[255,255,255]
ValueError: NumPy boolean array indexing assignment cannot assign 3 input values to the 51068 output values where the mask is true
Any solution? Anyone?