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.AsinhZScaleMapping Class Reference

A mapping for an asinh stretch, estimating the linear stretch by zscale. More...

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

Public Member Functions

def __init__ (self, image, Q=8, pedestal=None)
 Create an asinh mapping from an image, setting the linear part of the stretch using zscale. More...
 
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, estimating the linear stretch by zscale.

x = asinh(Q (I - z1)/(z2 - z1))/Q

See AsinhMapping

Definition at line 294 of file rgb.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.afw.display.rgb.AsinhZScaleMapping.__init__ (   self,
  image,
  Q = 8,
  pedestal = None 
)

Create an asinh mapping from an image, setting the linear part of the stretch using zscale.

Parameters
imageThe image to analyse, or a list of 3 images to be converted to an intensity image
QThe asinh softening parameter
pedestalThe value, or array of 3 values, to subtract from the images; or None

N.b. pedestal, if not None, is removed from the images when calculating the zscale stretch, and added back into Mapping.minimum[]

Definition at line 302 of file rgb.py.

302  def __init__(self, image, Q=8, pedestal=None):
303  """!
304  Create an asinh mapping from an image, setting the linear part of the stretch using zscale
305 
306  @param image The image to analyse, or a list of 3 images to be converted to an intensity image
307  @param Q The asinh softening parameter
308  @param pedestal The value, or array of 3 values, to subtract from the images; or None
309 
310  N.b. pedestal, if not None, is removed from the images when calculating the zscale
311  stretch, and added back into Mapping.minimum[]
312  """
313  try:
314  assert len(image) in (1, 3,), "Please provide 1 or 3 images"
315  except TypeError:
316  image = [image]
317 
318  if pedestal is not None:
319  try:
320  assert len(pedestal) in (
321  1, 3,), "Please provide 1 or 3 pedestals"
322  except TypeError:
323  pedestal = 3*[pedestal]
324 
325  image = list(image) # needs to be mutable
326  for i, im in enumerate(image):
327  if pedestal[i] != 0.0:
328  if hasattr(im, "getImage"):
329  im = im.getImage()
330  if hasattr(im, "getArray"):
331  im = im.getArray()
332 
333  image[i] = im - pedestal[i] # n.b. a copy
334  else:
335  pedestal = len(image)*[0.0]
336 
337  image = computeIntensity(*image)
338 
339  zscale = ZScaleMapping(image)
340  # zscale.minimum is always a triple
341  dataRange = zscale.maximum - zscale.minimum[0]
342  minimum = zscale.minimum
343 
344  for i, level in enumerate(pedestal):
345  minimum[i] += level
346 
347  AsinhMapping.__init__(self, minimum, dataRange, Q)
348  self._image = image # support self.makeRgbImage()
349 
350 
def computeIntensity(imageR, imageG=None, imageB=None)
Return a naive total intensity from the red, blue, and green intensities.
Definition: rgb.py:30
def __init__(self, minimum, dataRange, Q)
Definition: rgb.py:414
daf::base::PropertyList * list
Definition: fits.cc:819

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 
)
inherited
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: