1

How can I remove the red text from image,enter image description here

src = cv2.imread('original.png', cv2.IMREAD_UNCHANGED)
src[:,:,2] = np.zeros([src.shape[0], src.shape[1]])
#cv2.imwrite('changed.png',src) 

this does remove the red color but also gives it a blueish background,how can I fix this or maybe do it in a better way.

Ideally the output would be like this

output

1 Answers1

1

The problem is that your extracting the image's Red Component, and not the image's red channel itself. Try the following:

src = cv2.imread('original.png', cv2.IMREAD_UNCHANGED)
print(src.shape)

#extract red channel
red_channel = src[:,:,2]

#write red channel to greyscale image
cv2.imwrite('changed.png', red_channel)

Below you'll see resources that describe the difference. If you found this useful please mark as answer. Thanks

Resources:

TheoNeUpKID
  • 763
  • 7
  • 11
  • What changes should be made in the code if I want to keep only a particular color? Inmy case, I want to keep black color text only. – Virtuall.Kingg Dec 10 '21 at 05:08