def testLinear(self): """Test using a specified linear stretch""" rgbImage = rgb.LinearMapping(-8.45, 13.44).makeRgbImage(self.images[R]) if display: rgb.displayRGB(rgbImage)
def testStarsResizeSpecifications(self): """Test creating an RGB image changing the output """ rgbImages = [self.images[R], self.images[G], self.images[B]] map = rgb.AsinhZScaleMapping(rgbImages[0]) for xSize, ySize, frac in [ (self.images[R].getWidth() // 2, self.images[R].getHeight() // 2, None), (2 * self.images[R].getWidth(), None, None), (self.images[R].getWidth() // 2, None, None), (None, self.images[R].getHeight() // 2, None), (None, None, 0.5), (None, None, 2), ]: rgbImage = map.makeRgbImage(*rgbImages, xSize=xSize, ySize=ySize, rescaleFactor=frac) h, w = rgbImage.shape[0:2] self.assertTrue(xSize is None or xSize == w) self.assertTrue(ySize is None or ySize == h) self.assertTrue( frac is None or w == int(frac * self.images[R].getWidth()), "%g == %g" % (w, int((frac if frac else 1) * self.images[R].getWidth()))) if display: rgb.displayRGB(rgbImage)
def testSaturated(self): """Test interpolating saturated pixels""" satValue = 1000.0 for f in [R, G, B]: self.images[f] = saturate(self.images[f], satValue) rgb.replaceSaturatedPixels(self.images[R], self.images[G], self.images[B], 1, 2000) # # Check that we replaced those NaNs with some reasonable value # for f in [R, G, B]: self.assertTrue(np.isfinite(self.images[f].getImage().getArray()).all()) if False: ds9.mtv(self.images[B], frame=0, title="B") ds9.mtv(self.images[G], frame=1, title="G") ds9.mtv(self.images[R], frame=2, title="R") # # Prepare for generating an output file # for f in [R, G, B]: self.images[f] = self.images[f].getImage() asinhMap = rgb.AsinhMapping(self.min, self.range, self.Q) rgbImage = asinhMap.makeRgbImage(self.images[R], self.images[G], self.images[B]) if display: rgb.displayRGB(rgbImage)
def testStars(self): """Test creating an RGB image""" asinhMap = rgb.AsinhMapping(self.min, self.range, self.Q) rgbImage = asinhMap.makeRgbImage(self.images[R], self.images[G], self.images[B]) if display: rgb.displayRGB(rgbImage)
def display_image(image, contrast=1, figsize=(8, 8)): """Use matplotlib to plot an afw.image.Image.""" plt.figure(figsize=figsize) scaled_image = ZScaleMapping(image, contrast=contrast)\ .makeRgbImage(image, image, image) displayRGB(scaled_image) plt.axis('off')
def testStarsAsinhZscaleIntensityBW(self): """Test creating a black-and-white image using an asinh stretch estimated using zscale on the intensity""" rgbImage = rgb.AsinhZScaleMapping(self.images[R]).makeRgbImage() if display: rgb.displayRGB(rgbImage)
def testStarsAsinhZscaleIntensity(self): """Test creating an RGB image using an asinh stretch estimated using zscale on the intensity""" rgbImages = [self.images[R], self.images[G], self.images[B]] map = rgb.AsinhZScaleMapping(rgbImages) rgbImage = map.makeRgbImage(*rgbImages) if display: rgb.displayRGB(rgbImage)
def testLinearMinMax(self): """Test using a min/max linear stretch N.b. also checks that an image passed to the ctor is used as the default in makeRgbImage() """ rgbImage = rgb.LinearMapping(image=self.images[R]).makeRgbImage() if display: rgb.displayRGB(rgbImage)
def testStarsResizeToSize(self): """Test creating an RGB image of a specified size""" xSize = self.images[R].getWidth()//2 ySize = self.images[R].getHeight()//2 for rgbImages in ([self.images[R], self.images[G], self.images[B]], [afwImage.ImageU(_.getArray().astype('uint16')) for _ in [ self.images[R], self.images[G], self.images[B]]]): rgbImage = rgb.AsinhZScaleMapping(rgbImages[0]).makeRgbImage(*rgbImages, xSize=xSize, ySize=ySize) if display: rgb.displayRGB(rgbImage)
def testStarsAsinhZscaleIntensityPedestal(self): """Test creating an RGB image using an asinh stretch estimated using zscale on the intensity where the images each have a pedestal added""" rgbImages = [self.images[R], self.images[G], self.images[B]] pedestal = [100, 400, -400] for i, ped in enumerate(pedestal): rgbImages[i] += ped map = rgb.AsinhZScaleMapping(rgbImages, pedestal=pedestal) rgbImage = map.makeRgbImage(*rgbImages) if display: rgb.displayRGB(rgbImage)
def plotDeblendFamilyRGB(parent, bands=['g', 'r', 'i'], min=0.01, max=0.5, Q=8, rgbFileFmt=None): x, y = parent.getX(), parent.getY() fams = {} imBbox = afwGeom.BoxI() for bandName in "GRI".upper(): filterName = "HSC-%s" % bandName x0, y0 = coaddDict[filterName].getXY0() x0, y0 = 0, 0 fams[filterName] = familiesDict[filterName].find((x + x0, y + y0), matchRadius=20) if not fams[filterName]: return parent, kids = fams[filterName] bbox = parent.getFootprint().getBBox() for kid in kids: kim = footprintToImage(kid.getFootprint(), coaddDict[filterName].getMaskedImage()) bbox.include(kim.getBBox(afwImage.PARENT)) imBbox.include(bbox) images = {} for bandName in bands: filterName = "HSC-%s" % bandName.upper() images[bandName] = makeDeblendFamilyMosaic( coaddDict[filterName].getMaskedImage(), *fams[filterName], background=-0.1, imBbox=imBbox).makeMosaic(display=None) for bands in [bands]: B, G, R = bands rgb = afwRgb.makeRGB(images[R], images[G], images[B], min, max - min, Q) afwRgb.displayRGB(rgb, show=True) if rgbFileFmt: afwRgb.writeRGB(rgbFileFmt % "".join(bands), rgb)
def testZScale(self): """Test using a zscale stretch""" rgbImage = rgb.ZScaleMapping(self.images[R]).makeRgbImage() if display: plt = rgb.displayRGB(rgbImage, False) plt.title("zscale") plt.show()
def plotDeblendFamilyRGB(parent, bands=['g', 'r', 'i'], min=0.01, max=0.5, Q=8, rgbFileFmt=None): x, y = parent.getX(), parent.getY() fams = {} imBbox = afwGeom.BoxI() for bandName in "GRI".upper(): filterName = "HSC-%s" % bandName x0, y0 = coaddDict[filterName].getXY0() x0, y0 = 0, 0 fams[filterName] = familiesDict[filterName].find((x + x0, y + y0), matchRadius=20) if not fams[filterName]: return parent, kids = fams[filterName] bbox = parent.getFootprint().getBBox() for kid in kids: kim = footprintToImage(kid.getFootprint(), coaddDict[filterName].getMaskedImage()) bbox.include(kim.getBBox(afwImage.PARENT)) imBbox.include(bbox) images = {} for bandName in bands: filterName = "HSC-%s" % bandName.upper() images[bandName] = makeDeblendFamilyMosaic(coaddDict[filterName].getMaskedImage(), *fams[filterName], background=-0.1, imBbox=imBbox).makeMosaic(display=None) for bands in [bands]: B, G, R = bands rgb = afwRgb.makeRGB(images[R], images[G], images[B], min, max - min, Q) afwRgb.displayRGB(rgb, show=True) if rgbFileFmt: afwRgb.writeRGB(rgbFileFmt % "".join(bands), rgb)
def testStarsResizeSpecifications(self): """Test creating an RGB image changing the output """ rgbImages = [self.images[R], self.images[G], self.images[B]] map = rgb.AsinhZScaleMapping(rgbImages[0]) for xSize, ySize, frac in [(self.images[R].getWidth()/2, self.images[R].getHeight()/2, None), (2*self.images[R].getWidth(), None, None), (self.images[R].getWidth()/2, None, None), (None, self.images[R].getHeight()/2, None), (None, None, 0.5), (None, None, 2), ]: rgbImage = map.makeRgbImage(*rgbImages, xSize=xSize, ySize=ySize, rescaleFactor=frac) h, w = rgbImage.shape[0:2] self.assertTrue(xSize is None or xSize == w) self.assertTrue(ySize is None or ySize == h) self.assertTrue(frac is None or w == int(frac*self.images[R].getWidth()), "%g == %g" % (w, int((frac if frac else 1)*self.images[R].getWidth()))) if display: rgb.displayRGB(rgbImage)
def testStars2(self): """Test creating an RGB image using makeRGB""" rgbImage = rgb.makeRGB(self.images[R], self.images[G], self.images[B]) if display: rgb.displayRGB(rgbImage)