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

A linear map map of red, blue, green intensities into uint8 values. More...

Inheritance diagram for lsst.afw.display.rgb.LinearMapping:
lsst.afw.display.rgb.Mapping lsst.afw.display.rgb.ZScaleMapping

Public Member Functions

def __init__ (self, minimum=None, maximum=None, image=None)
 A linear stretch from [minimum, maximum]; if one or both are omitted use image minimum/maximum to set them. 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

 maximum
 
 minimum
 

Detailed Description

A linear map map of red, blue, green intensities into uint8 values.

Definition at line 192 of file rgb.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.afw.display.rgb.LinearMapping.__init__ (   self,
  minimum = None,
  maximum = None,
  image = None 
)

A linear stretch from [minimum, maximum]; if one or both are omitted use image minimum/maximum to set them.

Parameters
minimumIntensity that should be mapped to black (a scalar or array for R, G, B)
maximumIntensity that should be mapped to white (a scalar)
imageImage to estimate minimum/maximum if not explicitly set

Definition at line 195 of file rgb.py.

195  def __init__(self, minimum=None, maximum=None, image=None):
196  """!A linear stretch from [minimum, maximum]; if one or both are omitted use image minimum/maximum to set them
197 
198  @param minimum Intensity that should be mapped to black (a scalar or array for R, G, B)
199  @param maximum Intensity that should be mapped to white (a scalar)
200  @param image Image to estimate minimum/maximum if not explicitly set
201  """
202 
203  if minimum is None or maximum is None:
204  assert image is not None, "You must provide an image if you don't set both minimum and maximum"
205 
206  stats = afwMath.makeStatistics(image, afwMath.MIN | afwMath.MAX)
207  if minimum is None:
208  minimum = stats.getValue(afwMath.MIN)
209  if maximum is None:
210  maximum = stats.getValue(afwMath.MAX)
211 
212  Mapping.__init__(self, minimum, image)
213  self.maximum = maximum
214 
215  if maximum is None:
216  self._range = None
217  else:
218  assert maximum - minimum != 0, "minimum and maximum values must not be equal"
219  self._range = float(maximum - minimum)
220 
Statistics makeStatistics(lsst::afw::math::MaskedVector< EntryT > const &mv, std::vector< WeightPixel > const &vweights, int const flags, StatisticsControl const &sctrl=StatisticsControl())
The makeStatistics() overload to handle lsst::afw::math::MaskedVector<>
Definition: Statistics.h:520
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.LinearMapping.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 221 of file rgb.py.

221  def mapIntensityToUint8(self, intensity):
222  """Return an array which, when multiplied by an image, returns that image mapped to the range of a
223  uint8, [0, 255] (but not converted to uint8)
224 
225  The intensity is assumed to have had minimum subtracted (as that can be done per-band)
226  """
227  with np.errstate(invalid='ignore', divide='ignore'): # n.b. np.where can't and doesn't short-circuit
228  return np.where(intensity <= 0, 0,
229  np.where(intensity >= self._range,
230  self._uint8Max/intensity, self._uint8Max/self._range))
231 
232 

Member Data Documentation

◆ maximum

lsst.afw.display.rgb.LinearMapping.maximum

Definition at line 213 of file rgb.py.

◆ 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: