# Deringing lanczos4 interpolation

Hi, I’m trying to use lanczos4 interpolation for a homography transform on astronomical images. The algorithm as implemented causes ringing artefacts around stars in some images, so I’m experimenting with doing a second transform using bilinear interpolation (these algorithms don’t cause ringing) and using the result as a guide image, so I can clamp the pixels from the transform using lanczos4 interpolation to the values from the guide image if they are more than n% lower than the guide image pixel value.

Two questions:

1. Here’s my code:
``````	warpPerspective(in, out, H, Size(target_rx, target_ry), interpolation, BORDER_TRANSPARENT);
if (interpolation == OPENCV_LANCZOS4 || interpolation == OPENCV_CUBIC) {
// factor sets how big an undershoot can be tolerated
double factor = 0.75;
// Create guide image
warpPerspective(in, guide, H, Size(target_rx, target_ry), OPENCV_LINEAR, BORDER_TRANSPARENT);
// Compare the two, replace out pixels with guide pixels if too far out
for (int i = 0 ; i < out.rows ; i++) {
const double* outi = out.ptr<double>(i);
const double* guidei = guide.ptr<double>(i);
for (int j = 0; j < out.cols ; j++) {
if (outi[j] < guidei[j] * factor)
out.at<double>(i, j) = guidei[j];
}
}
``````

Is there a way of avoiding iterating across the elements of the Mat to do what I want?

1. Is there just a better way overall of achieving deringing?

Many thanks!

you compared individual pixels.

you should compare whole images.

use the mask image to compose the result: `src.copyTo(dst, mask)`