LSSTApplications  15.0+21,16.0+1,16.0+3,16.0+4,16.0+8,16.0-1-g2115a9e+2,16.0-1-g4515a79+6,16.0-1-g5c6f5ee+4,16.0-1-g7bb14cc,16.0-1-g80120d7+4,16.0-1-g98efed3+4,16.0-1-gb7f560d+1,16.0-14-gb4f0cd2fa,16.0-2-g1ad129e+1,16.0-2-g2ed7261+1,16.0-2-g311bfd2,16.0-2-g568a347+3,16.0-2-g852da13+6,16.0-2-gd4c87cb+3,16.0-3-g099ede0,16.0-3-g150e024+3,16.0-3-g1f513a6,16.0-3-g958ce35,16.0-4-g08dccf71+4,16.0-4-g128aaef,16.0-4-g84f75fb+5,16.0-4-gcfd1396+4,16.0-4-gde8cee2,16.0-4-gdfb0d14+1,16.0-5-g7bc0afb+3,16.0-5-g86fb31a+3,16.0-6-g2dd73041+4,16.0-7-g95fb7bf,16.0-7-gc37dbc2+4,w.2018.28
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | List of all members
lsst.afw.display.rgb.AsinhMapping Class Reference

A mapping for an asinh stretch (preserving colours independent of brightness) More...

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

Public Member Functions

def __init__ (self, minimum, dataRange, Q=8)
 
def mapIntensityToUint8 (self, intensity)
 
def makeRgbImage (self, imageR=None, imageG=None, imageB=None, xSize=None, ySize=None, rescaleFactor=None)
 Convert 3 arrays, imageR, imageG, and imageB into a numpy RGB image. More...
 
def intensity (self, imageR, imageG, imageB)
 Return the total intensity from the red, blue, and green intensities. More...
 

Public Attributes

 minimum
 

Detailed Description

A mapping for an asinh stretch (preserving colours independent of brightness)

x = asinh(Q (I - minimum)/range)/Q

This reduces to a linear stretch if Q == 0

See http://adsabs.harvard.edu/abs/2004PASP..116..133L

Definition at line 254 of file rgb.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.afw.display.rgb.AsinhMapping.__init__ (   self,
  minimum,
  dataRange,
  Q = 8 
)

Definition at line 264 of file rgb.py.

264  def __init__(self, minimum, dataRange, Q=8):
265  Mapping.__init__(self, minimum)
266 
267  # 32bit floating point machine epsilon; sys.float_info.epsilon is 64bit
268  epsilon = 1.0/2**23
269  if abs(Q) < epsilon:
270  Q = 0.1
271  else:
272  Qmax = 1e10
273  if Q > Qmax:
274  Q = Qmax
275 
276  if False:
277  self._slope = self._uint8Max/Q # gradient at origin is self._slope
278  else:
279  frac = 0.1 # gradient estimated using frac*range is _slope
280  self._slope = frac*self._uint8Max/np.arcsinh(frac*Q)
281 
282  self._soften = Q/float(dataRange)
283 
Angle abs(Angle const &a)
Definition: Angle.h:106
def __init__(self, minimum, dataRange, Q)
Definition: rgb.py:414

Member Function Documentation

◆ intensity()

def lsst.afw.display.rgb.Mapping.intensity (   self,
  imageR,
  imageG,
  imageB 
)
inherited

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

This is a naive computation, and may be overridden by subclasses

Definition at line 143 of file rgb.py.

143  def intensity(self, imageR, imageG, imageB):
144  """!Return the total intensity from the red, blue, and green intensities
145 
146  This is a naive computation, and may be overridden by subclasses
147  """
148  return computeIntensity(imageR, imageG, imageB)
149 
def computeIntensity(imageR, imageG=None, imageB=None)
Return a naive total intensity from the red, blue, and green intensities.
Definition: rgb.py:30

◆ makeRgbImage()

def lsst.afw.display.rgb.Mapping.makeRgbImage (   self,
  imageR = None,
  imageG = None,
  imageB = None,
  xSize = None,
  ySize = None,
  rescaleFactor = None 
)
inherited

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

Parameters
imageRImage to map to red (if None, use the image passed to the ctor)
imageGImage to map to green (if None, use imageR)
imageBImage to map to blue (if None, use imageR)
xSizeDesired width of RGB image (or None). If ySize is None, preserve aspect ratio
ySizeDesired height of RGB image (or None)
rescaleFactorMake size of output image rescaleFactor*size of the input image (or None)

N.b. images may be afwImage.Images or numpy arrays

Definition at line 87 of file rgb.py.

87  xSize=None, ySize=None, rescaleFactor=None):
88  """!Convert 3 arrays, imageR, imageG, and imageB into a numpy RGB image
89  @param imageR Image to map to red (if None, use the image passed to the ctor)
90  @param imageG Image to map to green (if None, use imageR)
91  @param imageB Image to map to blue (if None, use imageR)
92  @param xSize Desired width of RGB image (or None). If ySize is None, preserve aspect ratio
93  @param ySize Desired height of RGB image (or None)
94  @param rescaleFactor Make size of output image rescaleFactor*size of the input image (or None)
95 
96  N.b. images may be afwImage.Images or numpy arrays
97  """
98  if imageR is None:
99  if self._image is None:
100  raise RuntimeError(
101  "You must provide an image (or pass one to the constructor)")
102  imageR = self._image
103 
104  if imageG is None:
105  imageG = imageR
106  if imageB is None:
107  imageB = imageR
108 
109  imageRGB = [imageR, imageG, imageB]
110  for i, c in enumerate(imageRGB):
111  if hasattr(c, "getImage"):
112  c = imageRGB[i] = c.getImage()
113  if hasattr(c, "getArray"):
114  imageRGB[i] = c.getArray()
115 
116  if xSize is not None or ySize is not None:
117  assert rescaleFactor is None, "You may not specify a size and rescaleFactor"
118  h, w = imageRGB[0].shape
119  if ySize is None:
120  ySize = int(xSize*h/float(w) + 0.5)
121  elif xSize is None:
122  xSize = int(ySize*w/float(h) + 0.5)
123 
124  size = (ySize, xSize) # n.b. y, x order for scipy
125  elif rescaleFactor is not None:
126  size = float(rescaleFactor) # an int is intepreted as a percentage
127  else:
128  size = None
129 
130  if size is not None:
131  try:
132  import scipy.misc
133  except ImportError as e:
134  raise RuntimeError(
135  "Unable to rescale as scipy.misc is unavailable: %s" % e)
136 
137  for i, im in enumerate(imageRGB):
138  imageRGB[i] = scipy.misc.imresize(
139  im, size, interp='bilinear', mode='F')
140 
141  return np.dstack(self._convertImagesToUint8(*imageRGB)).astype(np.uint8)
142 

◆ mapIntensityToUint8()

def lsst.afw.display.rgb.AsinhMapping.mapIntensityToUint8 (   self,
  intensity 
)
Return an array which, when multiplied by an image, returns that image mapped to the range of a
uint8, [0, 255] (but not converted to uint8)

The intensity is assumed to have had minimum subtracted (as that can be done per-band)

Definition at line 284 of file rgb.py.

284  def mapIntensityToUint8(self, intensity):
285  """Return an array which, when multiplied by an image, returns that image mapped to the range of a
286  uint8, [0, 255] (but not converted to uint8)
287 
288  The intensity is assumed to have had minimum subtracted (as that can be done per-band)
289  """
290  with np.errstate(invalid='ignore', divide='ignore'): # n.b. np.where can't and doesn't short-circuit
291  return np.where(intensity <= 0, 0, np.arcsinh(intensity*self._soften)*self._slope/intensity)
292 
293 

Member Data Documentation

◆ minimum

lsst.afw.display.rgb.Mapping.minimum
inherited

Definition at line 83 of file rgb.py.


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