post · · 4 min read · By Jeff Neet
Smoothing a Milky Way timelapse with one rotation
Thirty photos of the Milky Way, two gaps, and four ways to stretch them into video. Generic in-between frames warp or ghost the stars. The sky turns about one point, so measure that turn and rotate the photos.
The usual advice for a short timelapse is to let software invent the missing frames. For a sky full of stars, that advice falls apart: one method smears the edges, another leaves double stars. The whole sky is doing one simple thing, turning about the celestial pole. Measure that turn once, and every in-between frame is a real photo rotated a little further.
The problem
One February morning on the South Island of New Zealand, I had a Canon EOS R10 on a tripod, pointed at the Milky Way: 18 mm, f/3.5, ISO 5000, 30-second exposures about 33 seconds apart. That gave 30 frames over 20 minutes, with two gaps in the sequence, one of 2 minutes and one of 3 minutes 16 seconds.
Thirty frames is one second of video at 30 fps. Each attempt below stretches it to about 3 seconds.
Attempt one: real frames only
Played at 10 frames a second, nothing is invented. It steps, and the stars hop at both gaps.
Attempt two: motion interpolation
ffmpeg’s minterpolate filter estimates how each block of pixels moves and paints new frames between the real ones. Mid-sky, it holds up. Toward the edges, where stars enter and leave the frame, it smears.
Attempt three: a halfway blend
Here every new frame is a 50/50 mix of its two neighbours. Nothing warps, because nothing moves. Stars show as faint pairs instead, and the gaps still jump, only softer.
What worked: rotate the sky
Stars don’t move independently. Over a few minutes the whole sky turns as one rigid piece about the celestial pole, at 15° an hour. From New Zealand that’s the south celestial pole, which has no bright star to mark it. So the job is to measure one rotation, not thousands of separate motions.
- Find stars. OpenCV’s corner detector picks about 3,000 bright points in a frame.
- Follow them. Pyramidal optical flow finds each point again in the next frame.
- Fit one rotation.
estimateAffinePartial2Dwith RANSAC fits a rotation, scale and shift to every match and throws out anything that disagrees. On screen it came to 0.104° per frame, steady across all 29 intervals, with the pivot just off the top-right corner each time. Across the gaps it measured 0.384° and 0.625°, matching the missing minutes. - Split sky from ground. Wherever the rotated frame matches the next photo better than the unrotated one is sky. The rest is foreground, and it stays put.
- Render. For a frame partway between two photos, turn the earlier photo forward by that fraction, turn the later one back by the rest, and mix the two. The ground just crossfades.
Three in-between frames per pair, and proportionally more across the gaps, comes to 148 frames, just under 5 seconds at 30 fps.
When the motion has a model, fit the model instead of guessing pixels.
The math
Take a star at in one frame and the same star at in the next. The fit looks for one turn , one scale and one shift that carry every star at once, where turns a point by about the origin:
RANSAC sets aside the stars that don’t agree, and the fit picks the values that leave the smallest total miss over the rest:
The sky only turns, so should come out at 1. The pivot is the one point the move leaves where it was, which gives it directly:
To render a frame a fraction of the way from photo to photo , turn forward by about , turn back by the rest, and mix them in proportion:
Here turns a whole image by about . At that’s photo untouched, and at it’s photo .
Here’s the heart of the fit, for two grayscale frames a and b:
# 1. Find stars: up to 3,000 bright points, at least 8 px apart,
# each at least 1% as strong as the brightest.
p = cv2.goodFeaturesToTrack(a, 3000, 0.01, 8, blockSize=5)
# 2. Follow them: find each star again in frame b.
# ok is 1 for every star it found.
q, ok, _ = cv2.calcOpticalFlowPyrLK(
a, b, p, None,
winSize=(31, 31), # search area around each star, in px
maxLevel=4, # coarse-to-fine levels, for bigger moves
)
# 3. Fit one rotation, scale and shift to every matched pair.
# RANSAC drops matches more than 1.5 px off the fit.
M, _ = cv2.estimateAffinePartial2D(
p[ok == 1], q[ok == 1],
method=cv2.RANSAC,
ransacReprojThreshold=1.5,
)
# The turn between frames, in radians.
angle = math.atan2(M[1, 0], M[0, 0])
# The pivot x satisfies x = Rx + t, so solve (I - R) x = t.
pivot = np.linalg.solve(np.eye(2) - M[:, :2], M[:, 2])
That last line is the pivot formula above, and it’s how the code finds the pole without being told where it is.
One thing to note: at 18 mm a single rigid rotation is close enough. On a fisheye, lens distortion bends the star paths, and you’d want to undistort the frames first.
Try it
Shoot a few minutes of stars from a tripod, keep the interval steady, and run the five steps above. If you want the finished clip to look smooth on a normal monitor, export at 30 or 60 fps. Other rates, like 40 on a 60 Hz screen, show frames for uneven lengths of time, and that reads as jitter in footage that’s actually steady.
