I keep getting an error message when I run this code and I don't know how to correct it.
Here's the code and below it is the error message:

import sys
import Image
import ImageFilter

im = Image.open("7.bmp").convert("L")
source = im.split()

R, G, B = 0, 1, 2

# select regions where red is less than 100
mask = source[R].point(lambda i: i < 100 and 255)

# process the green band
out = source[G].point(lambda i: i * 0.7)

# paste the processed band back, but only where red was < 100
source[G].paste(out, None, mask)

# build a new multiband image
im = Image.merge(im.mode, source)

Traceback (most recent call last):
File "C:\Python25\bmp.py", line 14, in <module>
out = source[G].point(lambda i: i * 0.7)
IndexError: tuple index out of range

Any suggestions? Thanks

Recommended Answers

All 3 Replies

In your code source is not a list or tuple. You can use a helper print source to look at it.

Hm....what I'm trying to work towards is take a simple bitmap that has horizontal lines in it of red,blue,green, red,blue, green and move the colors so the 2 reds are together, 2 blues, 2 greens and instead of 6 lines of colors, it's 3 doubled up lines.

I would take a look at the following lines. In the first line of code, "i < 100 and 255", what is "and 255" supposed to do? Also, I would add the print statement before the second line of code to see what is happening.

# select regions where red is less than 100
mask = source[R].point(lambda i: i < 100 and 255)

# process the green band
print "source =", len(source), G, source
out = source[G].point(lambda i: i * 0.7)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.