99 xSize=None, ySize=None, rescaleFactor=None):
100 """Convert 3 arrays, imageR, imageG, and imageB into a numpy RGB image
101
102 imageR : `lsst.afw.image.Image` or `numpy.ndarray`, (Nx, Ny)
103 Image to map to red (if `None`, use the image passed to the ctor)
104 imageG : `lsst.afw.image.Image` or `numpy.ndarray`, (Nx, Ny), optional
105 Image to map to green (if `None`, use imageR)
106 imageB : `lsst.afw.image.Image` or `numpy.ndarray`, (Nx, Ny), optional
107 Image to map to blue (if `None`, use imageR)
108 xSize : `int`, optional
109 Desired width of RGB image. If ``ySize`` is `None`, preserve aspect ratio
110 ySize : `int`, optional
111 Desired height of RGB image
112 rescaleFactor : `float`, optional
113 Make size of output image ``rescaleFactor*size`` of the input image
114 """
115 if imageR is None:
116 if self._image is None:
117 raise RuntimeError(
118 "You must provide an image (or pass one to the constructor)")
119 imageR = self._image
120
121 if imageG is None:
122 imageG = imageR
123 if imageB is None:
124 imageB = imageR
125
126 imageRGB = [imageR, imageG, imageB]
127 for i, c in enumerate(imageRGB):
128 if hasattr(c, "getImage"):
129 c = imageRGB[i] = c.getImage()
130 if hasattr(c, "getArray"):
131 imageRGB[i] = c.getArray()
132
133 if xSize is not None or ySize is not None:
134 assert rescaleFactor is None, "You may not specify a size and rescaleFactor"
135 h, w = imageRGB[0].shape
136 if ySize is None:
137 ySize = int(xSize*h/float(w) + 0.5)
138 elif xSize is None:
139 xSize = int(ySize*w/float(h) + 0.5)
140
141 size = (ySize, xSize)
142 elif rescaleFactor is not None:
143 size = float(rescaleFactor)
144 else:
145 size = None
146
147 if size is not None:
148 try:
149 import scipy.misc
150 except ImportError as e:
151 raise RuntimeError(
152 f"Unable to rescale as scipy.misc is unavailable: {e}")
153
154 for i, im in enumerate(imageRGB):
155 imageRGB[i] = scipy.misc.imresize(
156 im, size, interp='bilinear', mode='F')
157
158 return np.dstack(self._convertImagesToUint8(*imageRGB)).astype(np.uint8)
159