From c7e8e1ba7042ab475ec1ad118ddf41df136360c9 Mon Sep 17 00:00:00 2001 From: Thomas Boggs Date: Thu, 23 Apr 2015 00:00:11 -0400 Subject: [PATCH] Allow interpolated colors in default color scale [fixes #26]. * graphics/color_scale.py (HypercubeWindow.load_textures): Use 256 colors in the color scale. * graphics/colorscale.py (create_default_color_scale): Accept optional `ntics` argument to specirfy total number of colors. --- spectral/graphics/colorscale.py | 18 +++++++++++++++--- spectral/graphics/hypercube.py | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/spectral/graphics/colorscale.py b/spectral/graphics/colorscale.py index def3512..8e6185d 100644 --- a/spectral/graphics/colorscale.py +++ b/spectral/graphics/colorscale.py @@ -132,8 +132,16 @@ def set_range(self, min, max): self.span = max - min -def create_default_color_scale(): - '''Returns a black-blue-green-red-white color scale.''' +def create_default_color_scale(ntics=0): + '''Returns a black-blue-green-red-yellow-white color scale. + + Arguments: + + `ntics` (integer): + + Total number of colors in the scale. If this value is 0, no + interpolated colors will be used. + ''' from numpy import array mycolors = array([[0, 0, 0], [0, 0, 255], @@ -141,8 +149,12 @@ def create_default_color_scale(): [255, 0, 0], [255, 255, 0], [255, 255, 255]]) + + if ntics != 0 and ntics < len(mycolors): + raise ValueError('Any non-zero value of `ntics` must be greater than' + ' {}.'.format(len(mycolors))) levels = array([0., 10., 20., 30., 40., 50.]) - scale = ColorScale(levels, mycolors) + scale = ColorScale(levels, mycolors, ntics) return scale default_color_scale = create_default_color_scale() diff --git a/spectral/graphics/hypercube.py b/spectral/graphics/hypercube.py index 3bade20..770b229 100644 --- a/spectral/graphics/hypercube.py +++ b/spectral/graphics/hypercube.py @@ -227,14 +227,14 @@ def load_textures(self): import spectral from spectral.spectral import Image from . import graphics - from spectral.graphics.colorscale import default_color_scale + from spectral.graphics.colorscale import create_default_color_scale global DEFAULT_TEXTURE_SIZE if 'scale' in self.kwargs: scale = self.kwargs['scale'] else: - scale = default_color_scale + scale = create_default_color_scale(256) data = self.hsi s = data.shape