Reputation:
How can I remove the red text from image,
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
Upvotes: 1
Views: 2721
Reputation: 893
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:
Extract Red Component: https://pythonexamples.org/python-opencv-remove-red-channel-from-color-image/
Extract Red Channel: https://pythonexamples.org/python-opencv-extract-red-channel-of-image/
Upvotes: 1