Astronomical Data Analysis Software and Systems XIX
ASP Conference Series, Vol. XXX, 2009
Y. Mizumoto, K.-I. Morita, and M. Ohishi, eds.

P84

An algorithm of refinement of image alignment for image
subtraction
Masafumi Yagi
National Astronomical Observatory of Japan, Mitaka, Tokyo, 181-8588,
Japan
Abstract.
An algorithm is presented for estimating a shift between a pairof images. When subtracting a image from another image with a slight shift,
we recognize many positive-negative (bipolar) pattern around objects. The ideaof this study is to use the pattern for estimating the best alignment solution.
Moving one image around the other, we can draw many vectors toward the best
position, and estimate the best position as the intersection of the vectors.

1.

Introduction

It is required to take a difference of two images in some astronomical data analysis. One example is a narrow-line imaging; subtracting an off-band image from anon-band image to see a morphology of emission line regions. Another example isa search for moving objects; take a difference of different epochs to exclude staticobjects. In the image subtraction, several preprocesses are important, such asa point spread function (PSF) matching (e.g. Alard&Lupton 1998), a flux scale
matching, and a position alignment. If PSF size is mismatched, point sourcesin the difference image will have ring-shape. If flux scale is mismatched, mostof objects in the difference image are all positive/all negative, and target features disappear. And if a slight positional shift exists, positive-negative(bipolar)
patterns appear in the difference image.
Here I will present a method to estimate the relative positional shift between
two images using the positive-negative patterns, so that we can make a better
difference image. The method requires that the input images have similar PSF
and similar flux scale, because the positive-negative pattern does not appear if
the two input images have very different PSF or very different flux scale.
Hereafter, in subtraction of images, C = A − B, I will call A, B, and C
as the target image, the reference image, and the difference image, respectively.
The problem is how to align the target image(A) with the reference image(B).

2.

Basic Idea

Dealing with the difference images, I found that the distance between the positive
peak and the negative peak is almost independent of the amount of the shift. Ansimple example of one dimensional gaussian case is shown as follows. Assume1

2

Figure 1.
The difference of two PSFs with a small relative shifts. The PSF
is a double gaussian of FWHM=5 pixels. The relative shifts of x direction are0.001, 0.003, 0.01, 0.03, 0.1 and 0.3 pixels from left to right and from top tobottom, respectively.

that the profile of an object follows a gaussian;"#x2g(x) = exp − 2 .
2σIf the shift between the target and the reference is 2s, the profile in the difference
image is"#"#(x − s)2(x + s)2f (x) = exp −− exp −2σ 22σ 2
The peak position of the profile is obtained by solving f’(x)=0. The equation issimplified as sx−sx−(x − s)exp 2 + (x + s)exp= 0.
σσ2hi

If sx << σ 2 , we can approximate that exp σsx2 ∼ 1 + σsx2 . Substituting theapproximation to the equation, the solution x=±σ is obtained. In the case,sx << σ 2 is equivalent to s << σ. From numerical calculation, the exact
solutions are x = ±1.04σ and x = ±1.12σ for s = 0.5σ, and s = σ, respectively.
It means that if the relative shift s is smaller than σ, the distance between thepositive and the negative peaks in the difference image is ∼ 2σ, regardless of theamount of the shift s.
In Figure 1, 2D simulated difference images of slightly shifted PSFs areshown. The figure clearly shows that the change of shift does not affect theposition of the peaks. Meanwhile, the change of shift affects the S/N of positivenegative pattern.
3.

MethodThough the positive-negative pattern loses the information of the amount of theshift, the pattern holds the information of the direction of the shift. In Figure

3

Figure 2.
(left) Schematic figure of the method. If we know the direction ofthe shift at two positions, the intersection of the vectors is the answer. (right)
An example of real data. The artificial shift of x,y = 0,± 2 pixels are shown.
The position of the nine images corresponds to the shift. For example thetop-left image is the difference of (x,y)=(-2,+2) shifted target image and thereference. The vectors show the direction toward the possible answer.

1, for example, it is clear that the target image is slightly shifted rightward
compared with the reference image, since the positive pattern appears on theright of the negative pattern. The direction can be estimated by measuring theposition of the positive and the negative peaks in the difference image. The next
idea is to add artificial shifts to the subtracting image. The schematic figure
and the real data are shown in Figure 2 left.
The estimation of the direction has some error. I therefore make 9 patterns,
by adding artificial shifts by x,y = 0,± 2 pixels. In the example in Figure 2 right,
the answer is to the right in the original position. If we add x=+2 shift to thetarget data, the answer is to the left. We therefore know that the best answer lies
somewhere between x=0 and x=+2. The vectors intersects each other aroundthe best solution. An example is shown in Figure 3.
I adopted the truncated least squares (Rousseeuw 1984) for the evaluation
function for shift of (x,y), which is defined ase(x, y) =0.75N
Xdi (x, y)2 ,i=1

where di is the distance between (x,y) and a vector sorted in the increasingorder, and N is the number of the vectors. In this method, the vectors are 9,and 0.75N = 6 vectors are used in the function for reducing the effect of outliers.
The best position is estimated so that the e(x,y) is minimal.
4.

Results

The method is implemented as a C-program. The artificial shift of the target
image is implemented as a memory shift without any interpolation as the shifts
are integer. A connected-pixels method (e.g. Bertin & Arnouts 1996) is used for

4

Figure 3. The estimation of the best position. (left) 9 shifted position andvectors. The dots represents the shifted position and the best position. (right)
zoomed plot around the best position. The vectors do not intersect at a single
position, because of errors.

the peak detection. The vector from the positive peak to neighboring negativepeak is marked. The vector for the difference image is calculated as a medianof the vectors. The C-program estimates the shift between two 1k×1k floating
image in 0.5 sec with Intel Pen4 1.7GHz Linux machine. Then, a shift of thetarget image by a convolution of sinc function is performed for better difference
image. An example is shown in Figure 4.

Figure 4. (left)R-band image of Coma cluster. (center)Difference of narrowband image and the R-band image. Several positive-negative patterns exist
because of a bad position alignment. (right) After the position refinementwith this method. The positive-negative patterns almost disappear, and jetlike feature is now recognized from the galaxy at the left, which is a real
narrow-band feature.

The difficulties of the current implementation are 1) the preprocess of flux
matching of input images is required, and 2) the threshold of pattern detection
should be set manually. These points should be solved in future version.
References
Alard, C., Lupton, R. H. 1998, ApJ, 503, 325
Bertin, E., Arnouts, S. 1996, A&AS, 117, 393
Rousseuw, P. J. 1984, Journal of the American Statistical Association, 79, 871