Reputation: 73
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""
Upvotes: 4
Views: 9289
Reputation: 16309
Why not use scikit-image instead? It's vectorized:
from skimage.io import imread
image = imread(image)
negative = 255 - image
Upvotes: 3
Reputation: 3635
Your problem is that you are getting negative numbers. I think you should be doing 255 - x
rather than x - 255
Upvotes: 5