Reputation: 43
I'm using Python and Scipy to perform some basic image manipulation. I've made the image greyscale and subtracted it from a gaussian blur of itself as a form of edge detection. Now I'd like to make it look pretty when running the .imshow() command. If I use one of the default colormaps, for instance,
matplotlib.pyplot.imshow(lena, cmap='binary')
where lena is a matrix representing my image in question, the image appears washed out with a grey background. It looks quite a lot like this.
I would like the image to appear sharper, with only two real colors, white and black, and very little (or no) grey in between.
Since none of the other default colormaps in SciPy can do this, I figured I should make my own. But I'm afraid I don't fully grasp the documentation provided by scipy.
So let's say I have the colormap from the tutorial:
cdict = {'red': ((0.0, 0.0, 0.0),
(0.5, 1.0, 0.7),
(1.0, 1.0, 1.0)),
'green': ((0.0, 0.0, 0.0),
(0.5, 1.0, 0.0),
(1.0, 1.0, 1.0)),
'blue': ((0.0, 0.0, 0.0),
(0.5, 1.0, 0.0),
(1.0, 0.5, 1.0))}
my_cmap = matplotlib.colors.LinearSegmentedColormap('my_colormap', cdict, 256)
matplotlib.pyplot.imshow(lena, cmap=my_cmap)
How should this look if I want the colormap to be exclusively white from range 0 to .5, and exclusively black from range .5 to 1? Thanks to everyone for the help!
Upvotes: 1
Views: 468
Reputation: 335
I would expect something like this:
cdict = {'red': ((0.0, 0.0, 0.0),
(0.5, 0.0, 0.0),
(0.5, 1.0, 1.0),
(1.0, 1.0, 1.0)),
'green': ((0.0, 0.0, 0.0),
(0.5, 0.0, 0.0),
(0.5, 1.0, 1.0),
(1.0, 1.0, 1.0)),
'blue': ((0.0, 0.0, 0.0),
(0.5, 0.0, 0.0),
(0.5, 1.0, 1.0),
(1.0, 1.0, 1.0))}
See also: http://matplotlib.org/examples/pylab_examples/custom_cmap.html
Please excuse me if I'm wrong. I never created jumps like the one you want.
Upvotes: 1