def clipImage(im, minClip, maxClip): """Clip an image to lie between minClip and maxclip (None to ignore)""" if re.search("::MaskedImage<", im.__repr__()): mi = im else: mi = afwImage.makeMaskedImage(im, afwImage.MaskU(im.getDimensions())) if minClip is not None: ds = afwDetect.FootprintSet(mi, afwDetect.Threshold(-minClip, afwDetect.Threshold.VALUE, False)) afwDetect.setImageFromFootprintList(mi.getImage(), ds.getFootprints(), minClip) if maxClip is not None: ds = afwDetect.FootprintSet(mi, afwDetect.Threshold(maxClip)) afwDetect.setImageFromFootprintList(mi.getImage(), ds.getFootprints(), maxClip)
def clipImage(im, minClip, maxClip): """Clip an image to lie between minClip and maxclip (None to ignore)""" if isinstance(im, MaskedImage): mi = im else: mi = makeMaskedImage(im, Mask(im.getDimensions())) if minClip is not None: ds = afwDetect.FootprintSet( mi, afwDetect.Threshold(-minClip, afwDetect.Threshold.VALUE, False)) afwDetect.setImageFromFootprintList( mi.getImage(), ds.getFootprints(), minClip) if maxClip is not None: ds = afwDetect.FootprintSet(mi, afwDetect.Threshold(maxClip)) afwDetect.setImageFromFootprintList( mi.getImage(), ds.getFootprints(), maxClip)
def testSetFromFootprint(self): """Test setting mask/image pixels from a Footprint list""" mi = afwImage.MaskedImageF(afwGeom.Extent2I(12, 8)) im = mi.getImage() # # Objects that we should detect # self.objects = [] self.objects += [Object(10, [(1, 4, 4), (2, 3, 5), (3, 4, 4)])] self.objects += [Object(20, [(5, 7, 8), (5, 10, 10), (6, 8, 9)])] self.objects += [Object(20, [(6, 3, 3)])] im.set(0) # clear image for obj in self.objects: obj.insert(im) if False and display: ds9.mtv(mi, frame=0) ds = afwDetect.FootprintSet(mi, afwDetect.Threshold(15)) objects = ds.getFootprints() afwDetect.setMaskFromFootprintList(mi.getMask(), objects, 0x1) self.assertEqual(mi.getMask().get(4, 2), 0x0) self.assertEqual(mi.getMask().get(3, 6), 0x1) self.assertEqual(mi.getImage().get(3, 6), 20) afwDetect.setImageFromFootprintList(mi.getImage(), objects, 5.0) self.assertEqual(mi.getImage().get(4, 2), 10) self.assertEqual(mi.getImage().get(3, 6), 5) if display: ds9.mtv(mi, frame=1) # # Check Footprint.contains() while we are about it # self.assertTrue(objects[0].contains(afwGeom.Point2I(7, 5))) self.assertFalse(objects[0].contains(afwGeom.Point2I(10, 6))) self.assertFalse(objects[0].contains(afwGeom.Point2I(7, 6))) self.assertFalse(objects[0].contains(afwGeom.Point2I(4, 2))) self.assertTrue(objects[1].contains(afwGeom.Point2I(3, 6)))
def testSetFromFootprint(self): """Test setting mask/image pixels from a Footprint list""" mi = afwImage.MaskedImageF(afwGeom.Extent2I(12, 8)) im = mi.getImage() # # Objects that we should detect # self.objects = [] self.objects += [Object(10, [(1, 4, 4), (2, 3, 5), (3, 4, 4)])] self.objects += [Object(20, [(5, 7, 8), (5, 10, 10), (6, 8, 9)])] self.objects += [Object(20, [(6, 3, 3)])] im.set(0) # clear image for obj in self.objects: obj.insert(im) if False and display: ds9.mtv(mi, frame=0) ds = afwDetect.makeFootprintSet(mi, afwDetect.Threshold(15)) objects = ds.getFootprints() afwDetect.setMaskFromFootprintList(mi.getMask(), objects, 0x1) self.assertEqual(mi.getMask().get(4, 2), 0x0) self.assertEqual(mi.getMask().get(3, 6), 0x1) self.assertEqual(mi.getImage().get(3, 6), 20) afwDetect.setImageFromFootprintList(mi.getImage(), objects, 5.0) self.assertEqual(mi.getImage().get(4, 2), 10) self.assertEqual(mi.getImage().get(3, 6), 5) if False and display: ds9.mtv(mi, frame=1) # # Check Footprint.contains() while we are about it # self.assertTrue(objects[0].contains(afwGeom.Point2I(7, 5))) self.assertFalse(objects[0].contains(afwGeom.Point2I(10, 6))) self.assertFalse(objects[0].contains(afwGeom.Point2I(7, 6))) self.assertFalse(objects[0].contains(afwGeom.Point2I(4, 2))) self.assertTrue(objects[1].contains(afwGeom.Point2I(3, 6)))