82 """Interpolate over bad pixels in a masked image.
84 This modifies the ``image`` attribute of the ``maskedImage`` in place.
85 This method returns, and accepts, the coordinates of the bad pixels
86 that were interpolated over, and the coordinates and values of the
87 good pixels that were used to construct the interpolant. This avoids
88 having to search for the bad and the good pixels repeatedly when the
89 mask plane is shared among many images, as would be the case with
94 maskedImage : `~lsst.afw.image.MaskedImageF`
95 Image on which to perform interpolation (and modify in-place).
96 badpix: `numpy.ndarray`, optional
97 N x 3 numpy array, where N is the number of bad pixels.
98 The coordinates of the bad pixels to interpolate over in the first
99 two columns, and the pixel values (unused) in the third column.
100 If None, then the coordinates of the bad pixels are determined by
101 an exhaustive search over the image. If ``goodpix`` is not
102 provided, then this parameter is ignored.
103 goodpix: `numpy.ndarray`, optional
104 M x 3 numpy array, where M is the number of good pixels.
105 The first two columns are the coordinates of the good pixels around
106 ``badpix`` that must be included when constructing the interpolant.
107 the interpolant. The values are populated from the image plane of
108 the ``maskedImage`` and returned (provided values will be ignored).
109 If ``badpix`` is not provided, then this parameter is ignored.
113 badpix: `numpy.ndarray`
114 N x 3 numpy array, where N is the number of bad pixels.
115 The coordinates of the bad pixels that were interpolated over are
116 in the first two columns, and the corresponding pixel values in the
117 third. If ``badpix`` was provided, this is the same as the input.
118 goodpix: `numpy.ndarray`
119 M x 3 numpy array, where M is the number of bad pixels.
120 The coordinates of the good pixels that were used to construct the
121 interpolant arein the first two columns, and the corresponding
122 pixel values in the third. If ``goodpix`` was provided, the first
123 two columns are same as the input, with the third column updated
124 with the pixel values from the image plane of the ``maskedImage``.
127 if badpix
is None or goodpix
is None:
128 badpix, goodpix = ctUtils.findGoodPixelsAroundBadPixels(
130 self.config.badMaskPlanes,
131 buffer=self.config.interpLength,
136 ctUtils.updateArrayFromImage(goodpix, maskedImage.image)
139 if self.config.flipXY:
140 anchor_points = list(zip(goodpix[:, 1], goodpix[:, 0]))
141 query_points = badpix[:, 1::-1]
143 anchor_points = list(zip(goodpix[:, 0], goodpix[:, 1]))
144 query_points = badpix[:, :2]
146 interpolator = CloughTocher2DInterpolator(
149 fill_value=self.config.fillValue,
153 badpix[:, 2] = interpolator(query_points)
156 ctUtils.updateImageFromArray(maskedImage.image, badpix)
158 return badpix, goodpix