LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Private Member Functions | Private Attributes | List of all members
lsst.afw.display.rgb.Mapping Class Reference

Baseclass to map red, blue, green intensities into uint8 values. More...

Inheritance diagram for lsst.afw.display.rgb.Mapping:
lsst.afw.display.rgb.AsinhMapping

Public Member Functions

def __init__
 Create a mapping. More...
 
def makeRgbImage
 Convert 3 arrays, imageR, imageG, and imageB into a numpy RGB image. More...
 
def intensity
 Return the total intensity from the red, blue, and green intensities. More...
 
def mapIntensityToUint8
 

Private Member Functions

def _convertImagesToUint8
 

Private Attributes

 _uint8Max
 
 _min
 

Detailed Description

Baseclass to map red, blue, green intensities into uint8 values.

Definition at line 5 of file rgb.py.

Constructor & Destructor Documentation

def lsst.afw.display.rgb.Mapping.__init__ (   self,
  min 
)

Create a mapping.

Parameters
minIntensity that should be mapped to black (a scalar or array for R, G, B)

Definition at line 8 of file rgb.py.

8 
9  def __init__(self, min):
10  """!Create a mapping
11  \param min Intensity that should be mapped to black (a scalar or array for R, G, B)
12  """
13 
14  self._uint8Max = float(np.iinfo(np.uint8).max)
15 
16  try:
17  len(min)
18  except:
19  min = 3*[min]
20  assert len(min) == 3, "Please provide 1 or 3 values for min"
21 
22  self._min = min
def __init__
Create a mapping.
Definition: rgb.py:8

Member Function Documentation

def lsst.afw.display.rgb.Mapping._convertImagesToUint8 (   self,
  imageR,
  imageG,
  imageB 
)
private
Use the mapping to convert images imageR, imageG, and imageB to a triplet of uint8 images

Definition at line 45 of file rgb.py.

45 
46  def _convertImagesToUint8(self, imageR, imageG, imageB):
47  """Use the mapping to convert images imageR, imageG, and imageB to a triplet of uint8 images"""
48  imageR = imageR - self._min[0] # n.b. makes copy
49  imageG = imageG - self._min[1]
50  imageB = imageB - self._min[2]
51 
52  fac = self.mapIntensityToUint8(self.intensity(imageR, imageG, imageB))
53 
54  imageRGB = [imageR, imageG, imageB]
55 
56  for c in imageRGB:
57  c *= fac
58  c[c <= 0] = 0
59 
60  pixmax = self._uint8Max
61  r0, g0, b0 = imageRGB # copies -- could work row by row to minimise memory usage
62 
63  with np.errstate(invalid='ignore', divide='ignore'): # n.b. np.where doesn't (and can't) short-circuit
64  for i, c in enumerate(imageRGB):
65  c = np.where(r0 > g0,
66  np.where(r0 > b0,
67  np.where(r0 >= pixmax, c*pixmax/r0, c),
68  np.where(b0 >= pixmax, c*pixmax/b0, c)),
69  np.where(g0 > b0,
70  np.where(g0 >= pixmax, c*pixmax/g0, c),
71  np.where(b0 >= pixmax, c*pixmax/b0, c))).astype(np.uint8)
72  c[c > pixmax] = pixmax
73 
74  imageRGB[i] = c
75 
76  return imageRGB
def intensity
Return the total intensity from the red, blue, and green intensities.
Definition: rgb.py:37
def lsst.afw.display.rgb.Mapping.intensity (   self,
  imageR,
  imageG,
  imageB 
)

Return the total intensity from the red, blue, and green intensities.

Definition at line 37 of file rgb.py.

37 
38  def intensity(self, imageR, imageG, imageB):
39  """!Return the total intensity from the red, blue, and green intensities"""
40  return (imageR + imageG + imageB)/float(3);
def intensity
Return the total intensity from the red, blue, and green intensities.
Definition: rgb.py:37
def lsst.afw.display.rgb.Mapping.makeRgbImage (   self,
  imageR,
  imageG,
  imageB 
)

Convert 3 arrays, imageR, imageG, and imageB into a numpy RGB image.

N.b. images may be afwImages or numpy arrays

Definition at line 23 of file rgb.py.

23 
24  def makeRgbImage(self, imageR, imageG, imageB):
25  """!Convert 3 arrays, imageR, imageG, and imageB into a numpy RGB image
26 
27  N.b. images may be afwImages or numpy arrays
28  """
29  imageRGB = [imageR, imageG, imageB]
30  for i, c in enumerate(imageRGB):
31  if hasattr(c, "getImage"):
32  c = imageRGB[i] = c.getImage()
33  if hasattr(c, "getArray"):
34  imageRGB[i] = c.getArray()
35 
36  return np.flipud(np.dstack(self._convertImagesToUint8(*imageRGB)).astype(np.uint8))
def makeRgbImage
Convert 3 arrays, imageR, imageG, and imageB into a numpy RGB image.
Definition: rgb.py:23
def lsst.afw.display.rgb.Mapping.mapIntensityToUint8 (   self,
  I 
)
Map an intensity into the range of a uint8, [0, 255] (but not converted to uint8)

Definition at line 41 of file rgb.py.

41 
42  def mapIntensityToUint8(self, I):
43  """Map an intensity into the range of a uint8, [0, 255] (but not converted to uint8)"""
44  return np.where(I <= 0, 0, np.where(I < self._uint8Max, I, self._uint8Max))

Member Data Documentation

lsst.afw.display.rgb.Mapping._min
private

Definition at line 21 of file rgb.py.

lsst.afw.display.rgb.Mapping._uint8Max
private

Definition at line 13 of file rgb.py.


The documentation for this class was generated from the following file: