I understand to make an image negative, you have to change the RGB values so that the current value is being subtracted from 255.
What is wrong with my following code?
def negative(im):
height=len(im)
width = len(im[0])
for row in range(height):
for col in range(width):
red = im[row][col][0] - 255
green = im[row][col][1] - 255
blue = im[row][col][2] - 255
im[row][col]=[red,green,blue]
return im
It returns the error "TclError: can't parse color "#-1d-c-2""
Your problem is that you are getting negative numbers. I think you should be doing 255 - x
rather than x - 255
Why not use scikit-image instead? It's vectorized:
from skimage.io import imread
image = imread(image)
negative = 255 - image
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With