ingenuitas/SimpleCV — pull request #294 by salil93 (2013-02-12 09:20:08+00:00)
Title: Color Map Class improved

Tried to improve the ColorMap class in Color.py

Firstly, the color values that it used to return used to go out of the specified range of colors. This has been taken care of by putting a check.

Second, Earlier it used to map between only two colors, now we can map n number of colors. It takes in a tuple of colors. If only one color is specified, by default it will take White as the second color

cm = ColorMap(color = (Color.RED,Color.BLUE,Color.CYAN),2,4)
cm = ColorMap(color = (Color.ORANGE),0,1)

Using with more than 2 colors

cm = ColorMap(color = (Color.RED,Color.BLUE,Color.CYAN),2,4)
cm[2] #Returns RED color
cm[2.5] #Returns something between RED and BLUE
cm[3] #Returns BLUE color
cm[3.7] #Returns something between BLUE and CYAN
cm[4] #Returns CYAN color

Example

img = Image('../sampleimages/mtest.png')
blobs = img.findBlobs()
cm=ColorMap((Color.RED,Color.YELLOW,Color.BLUE),min(blobs.area()),max(blobs.area()))
for b in blobs:
b.draw(cm[b.area()])

![test_color_map0](https://f.cloud.github.com/assets/1548906/148155/da76fbf2-74f3-11e2-97bf-d92964ac87ab.jpg)