38def getSpanSetFromImages(images, thresh=0, xy0=None):
39 """Create a Footprint from a set of Images
40
41 Parameters
42 ----------
43 images : `lsst.afw.image.MultibandImage` or list of `lsst.afw.image.Image`, array
44 Images to extract the footprint from
45 thresh : `float`
46 All pixels above `thresh` will be included in the footprint
47 xy0 : `lsst.geom.Point2I`
48 Location of the minimum value of the images bounding box
49 (if images is an array, otherwise the image bounding box is used).
50
51 Returns
52 -------
53 spans : `lsst.afw.geom.SpanSet`
54 Union of all spans in the images above the threshold
55 imageBBox : `lsst.afw.detection.Box2I`
56 Bounding box for the input images.
57 """
58
59 if not hasattr(thresh, "__len__"):
60 thresh = [thresh] * len(images)
61
62
63
64 if isinstance(images, MultibandBase) or isinstance(images[0], Image):
65 spans = SpanSet()
66 for n, image in enumerate(images):
67 mask = image.array > thresh[n]
68 mask = Mask(mask.astype(np.int32), xy0=image.getBBox().getMin())
69 spans = spans.union(SpanSet.fromMask(mask))
70 imageBBox = images[0].getBBox()
71 else:
72
73 thresh = np.array(thresh)
74 if xy0 is None:
75 xy0 = Point2I(0, 0)
76 mask = np.any(images > thresh[:, None, None], axis=0)
77 mask = Mask(mask.astype(np.int32), xy0=xy0)
78 spans = SpanSet.fromMask(mask)
79 imageBBox = mask.getBBox()
80 return spans, imageBBox
81
82