I am working in a project which involves recognition of characters in an image. I need to switch the dark parts of the image to light, and the light parts to dark (or black), because the program uses light as background and dark as leters. Can anybody please tell me any Script which helps me doing that? Either in JavaScript or in Python. Thank you.
2 に答える
2
You will need some library to read the image like opencv. Since usually white is 255, use this to invert the colors:
import cv2
image = cv2.imread('imagefile.jpg')
image = 255 - image
cv2.imwrite('inverted.jpg')
于 2013-01-09T01:23:32.217 に答える
0
To do image-processing in Python, you can use OpenCV(cv2), NumPy & SciPy, scikit-image...
First, you read your image from file into a NumPy array. And then you can reverse the image by (255 - img). Here is some sample code:
from pylab import imshow
import cv2
img = cv2.imread("test.png")
rimg = 255 - img
imshow(rimg)
于 2013-01-09T01:19:23.920 に答える