23 __all__ = [
"clipImage",
"resetFilters",
"defineFilter",
24 "projectImage",
"getProjectionIndices"]
29 from .maskedImage
import MaskedImage, makeMaskedImage
30 from .image
import Mask
31 from .filter
import Filter, FilterProperty
35 """Clip an image to lie between minClip and maxclip (None to ignore)"""
36 if isinstance(im, MaskedImage):
41 if minClip
is not None:
44 afwDetect.setImageFromFootprintList(
45 mi.getImage(), ds.getFootprints(), minClip)
47 if maxClip
is not None:
49 afwDetect.setImageFromFootprintList(
50 mi.getImage(), ds.getFootprints(), maxClip)
54 """Reset registry of filters and filter properties"""
56 FilterProperty.reset()
59 def defineFilter(name, lambdaEff, lambdaMin=np.nan, lambdaMax=np.nan, alias=[], force=False):
60 """Define a filter and its properties in the filter registry"""
61 prop = FilterProperty(name, lambdaEff, lambdaMin, lambdaMax, force)
63 if isinstance(alias, str):
64 Filter.defineAlias(name, alias)
67 Filter.defineAlias(name, a)
71 """Get the indices to project an image
73 Given an image and target bounding box,
74 calculate the indices needed to appropriately
75 slice the input image and target image to
76 project the image to the target.
81 Bounding box of the input image
83 Bounding box of the target image
88 Slices of the target image in the form (by, bx), (iy, ix).
90 Slices of the input image in the form (by, bx), (iy, ix).
93 """Get minimum indices"""
100 return bxStart, ixStart
103 """Get maximum indices"""
114 dXmin = targetBBox.getMinX() - imageBBox.getMinX()
115 dXmax = targetBBox.getMaxX() - imageBBox.getMaxX()
116 dYmin = targetBBox.getMinY() - imageBBox.getMinY()
117 dYmax = targetBBox.getMaxY() - imageBBox.getMaxY()
119 bxStart, ixStart = getMin(dXmin)
120 byStart, iyStart = getMin(dYmin)
121 bxEnd, ixEnd = getMax(dXmax)
122 byEnd, iyEnd = getMax(dYmax)
124 bx = slice(bxStart, bxEnd)
125 by = slice(byStart, byEnd)
126 ix = slice(ixStart, ixEnd)
127 iy = slice(iyStart, iyEnd)
128 return (by, bx), (iy, ix)
132 """Project an image into a bounding box
134 Return a new image whose pixels are equal to those of
135 `image` within `bbox`, and equal to `fill` outside.
139 image: `afw.Image` or `afw.MaskedImage`
142 The bounding box to project onto.
144 The value to fill the region of the new
145 image outside the bounding box of the original.
149 newImage: `afw.Image` or `afw.MaskedImage`
150 The new image with the input image projected
151 into its bounding box.
153 if image.getBBox() == bbox:
157 if isinstance(image, MaskedImage):
158 newImage =
type(image.image)(bbox)
159 newImage.array[by, bx] = image.image.array[iy, ix]
160 newMask =
type(image.mask)(bbox)
161 newMask.array[by, bx] = image.mask.array[iy, ix]
162 newVariance =
type(image.image)(bbox)
163 newVariance.array[by, bx] = image.variance.array[iy, ix]
164 newImage =
MaskedImage(image=newImage, mask=newMask, variance=newVariance, dtype=newImage.array.dtype)
166 newImage =
type(image)(bbox)
169 newImage.array[by, bx] = image.array[iy, ix]