22 __all__ = [
"clipImage",
"resetFilters",
"defineFilter",
23 "projectImage",
"getProjectionIndices"]
25 from deprecated.sphinx
import deprecated
30 from .maskedImage
import MaskedImage, makeMaskedImage
31 from .image
import Mask
32 from ._filter
import Filter, FilterProperty
36 """Clip an image to lie between minClip and maxclip (None to ignore)"""
37 if isinstance(im, MaskedImage):
42 if minClip
is not None:
43 ds = afwDetect.FootprintSet(
44 mi, afwDetect.Threshold(-minClip, afwDetect.Threshold.VALUE,
False))
45 afwDetect.setImageFromFootprintList(
46 mi.getImage(), ds.getFootprints(), minClip)
48 if maxClip
is not None:
49 ds = afwDetect.FootprintSet(mi, afwDetect.Threshold(maxClip))
50 afwDetect.setImageFromFootprintList(
51 mi.getImage(), ds.getFootprints(), maxClip)
54 @deprecated(reason=("Removed with no replacement (FilterLabels do not need to be reset).
"
55 " Will be removed after v22."), category=FutureWarning, version=
"v22")
57 """Reset registry of filters and filter properties"""
59 FilterProperty.reset()
62 @deprecated(reason=("Removed with no replacement (but see lsst::afw::image::TransmissionCurve for how to set"
"and retrieve filter wavelength information). Will be removed after v22.
"),
63 category=FutureWarning, version="v22")
64 def defineFilter(name, lambdaEff, lambdaMin=np.nan, lambdaMax=np.nan, alias=[], force=False):
65 """Define a filter and its properties in the filter registry"""
66 prop =
FilterProperty(name, lambdaEff, lambdaMin, lambdaMax, force)
68 if isinstance(alias, str):
69 Filter.defineAlias(name, alias)
72 Filter.defineAlias(name, a)
76 """Get the indices to project an image
78 Given an image and target bounding box,
79 calculate the indices needed to appropriately
80 slice the input image and target image to
81 project the image to the target.
86 Bounding box of the input image
88 Bounding box of the target image
93 Slices of the target image in the form (by, bx), (iy, ix).
95 Slices of the input image in the form (by, bx), (iy, ix).
98 """Get minimum indices"""
105 return bxStart, ixStart
108 """Get maximum indices"""
119 dXmin = targetBBox.getMinX() - imageBBox.getMinX()
120 dXmax = targetBBox.getMaxX() - imageBBox.getMaxX()
121 dYmin = targetBBox.getMinY() - imageBBox.getMinY()
122 dYmax = targetBBox.getMaxY() - imageBBox.getMaxY()
124 bxStart, ixStart = getMin(dXmin)
125 byStart, iyStart = getMin(dYmin)
126 bxEnd, ixEnd = getMax(dXmax)
127 byEnd, iyEnd = getMax(dYmax)
129 bx = slice(bxStart, bxEnd)
130 by = slice(byStart, byEnd)
131 ix = slice(ixStart, ixEnd)
132 iy = slice(iyStart, iyEnd)
133 return (by, bx), (iy, ix)
137 """Project an image into a bounding box
139 Return a new image whose pixels are equal to those of
140 `image` within `bbox`, and equal to `fill` outside.
144 image: `afw.Image` or `afw.MaskedImage`
147 The bounding box to project onto.
149 The value to fill the region of the new
150 image outside the bounding box of the original.
154 newImage: `afw.Image` or `afw.MaskedImage`
155 The new image with the input image projected
156 into its bounding box.
158 if image.getBBox() == bbox:
162 if isinstance(image, MaskedImage):
163 newImage =
type(image.image)(bbox)
164 newImage.array[by, bx] = image.image.array[iy, ix]
165 newMask =
type(image.mask)(bbox)
166 newMask.array[by, bx] = image.mask.array[iy, ix]
167 newVariance =
type(image.image)(bbox)
168 newVariance.array[by, bx] = image.variance.array[iy, ix]
169 newImage =
MaskedImage(image=newImage, mask=newMask, variance=newVariance, dtype=newImage.array.dtype)
171 newImage =
type(image)(bbox)
174 newImage.array[by, bx] = image.array[iy, ix]
176
Represent a 2-dimensional array of bitmask pixels.
def clipImage(im, minClip, maxClip)
def getProjectionIndices(imageBBox, targetBBox)
def defineFilter(name, lambdaEff, lambdaMin=np.nan, lambdaMax=np.nan, alias=[], force=False)
def projectImage(image, bbox, fill=0)
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT >> image, typename std::shared_ptr< Mask< MaskPixelT >> mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT >> variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.