Skip to content

Commit

Permalink
Allow interpolated colors in default color scale [fixes spectralpytho…
Browse files Browse the repository at this point in the history
…n#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.
  • Loading branch information
tboggs committed Apr 23, 2015
1 parent 8ff6614 commit c7e8e1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions spectral/graphics/colorscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,29 @@ 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],
[0, 255, 0],
[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()
4 changes: 2 additions & 2 deletions spectral/graphics/hypercube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c7e8e1b

Please sign in to comment.