3 from lsst.afw.display.displayLib
import replaceSaturatedPixels
6 """!Baseclass to map red, blue, green intensities into uint8 values"""
10 \param min Intensity that should be mapped to black (a scalar or array for R, G, B)
19 assert len(min) == 3,
"Please provide 1 or 3 values for min"
24 """!Convert 3 arrays, imageR, imageG, and imageB into a numpy RGB image
26 N.b. images may be afwImages or numpy arrays
28 imageRGB = [imageR, imageG, imageB]
29 for i, c
in enumerate(imageRGB):
30 if hasattr(c,
"getImage"):
31 c = imageRGB[i] = c.getImage()
32 if hasattr(c,
"getArray"):
33 imageRGB[i] = c.getArray()
38 """!Return the total intensity from the red, blue, and green intensities"""
39 return (imageR + imageG + imageB)/float(3);
42 """Map an intensity into the range of a uint8, [0, 255] (but not converted to uint8)"""
46 """Use the mapping to convert images imageR, imageG, and imageB to a triplet of uint8 images"""
47 imageR = imageR - self.
_min[0]
48 imageG = imageG - self.
_min[1]
49 imageB = imageB - self.
_min[2]
53 imageRGB = [imageR, imageG, imageB]
62 with np.errstate(invalid=
'ignore', divide=
'ignore'):
63 for i, c
in enumerate(imageRGB):
66 np.where(r0 >= pixmax, c*pixmax/r0, c),
67 np.where(b0 >= pixmax, c*pixmax/b0, c)),
69 np.where(g0 >= pixmax, c*pixmax/g0, c),
70 np.where(b0 >= pixmax, c*pixmax/b0, c))).astype(np.uint8)
71 c[c > pixmax] = pixmax
78 """!A mapping for an asinh stretch (preserving colours independent of brightness)
80 x = asinh(Q (I - min)/range)/Q
82 This reduces to a linear stretch if Q == 0
84 See http://adsabs.harvard.edu/abs/2004PASP..116..133L
88 Mapping.__init__(self, min)
107 return np.where(I <= 0, 0, np.arcsinh(I*self.
_soften)*self.
_slope/I)
109 def makeRGB(imageR, imageG, imageB, min=0, range=5, Q=20, fileName=None,
110 saturatedBorderWidth=0, saturatedPixelValue=
None):
111 """Make a set of three images into an RGB image using an asinh stretch and optionally write it to disk
113 If saturatedBorderWidth is non-zero, replace saturated pixels with saturatedPixelValue. Note
114 that replacing saturated pixels requires that the input images be MaskedImages.
116 if saturatedBorderWidth:
117 if saturatedPixelValue
is None:
118 raise ValueError(
"saturatedPixelValue must be set if saturatedBorderWidth is set")
122 rgb = asinhMap.makeRgbImage(imageR, imageG, imageB)
129 """Display an rgb image using matplotlib"""
130 import matplotlib.pyplot
as plt
131 plt.imshow(rgb, interpolation=
'nearest')
135 """Write an RGB image (made by e.g. makeRGB) to fileName"""
136 import matplotlib.image
137 matplotlib.image.imsave(fileName, rgbImage)
150 def __init__(self, imageR, imageG, imageB, mapping):
151 asinh =
AsinhMapping(mapping.min, mapping.range, mapping.Q)
152 self.
rgb = asinh.makeRgbImage(imageR, imageG, imageB)
158 return _RgbImageF(imageR, imageG, imageB, mapping)
def intensity
Return the total intensity from the red, blue, and green intensities.
Baseclass to map red, blue, green intensities into uint8 values.
def makeRgbImage
Convert 3 arrays, imageR, imageG, and imageB into a numpy RGB image.
def _convertImagesToUint8
def __init__
Create a mapping.
A mapping for an asinh stretch (preserving colours independent of brightness)
template void replaceSaturatedPixels(image::MaskedImage< float > &rim, image::MaskedImage< float > &gim, image::MaskedImage< float > &bim, int borderWidth, float saturatedPixelValue)