Lens distortion

217 views
Skip to first unread message

Mark

unread,
Jun 15, 2023, 8:54:22 AM6/15/23
to astrometry
Hi everyone.

Using the astrometry.net solve field with appropriate tweak order (in my case, tw=4) I managed to obtain a SIP coefficient that, I believe, truly represents distortion on my lens.
The average solving precision(the average distance between the field and index stars) is around 1/4 of a pixel which is a pretty amazing result.
For the new images, taken with the same camera, I can undistort starfield by hand using previously obtained SIP coefficients(A and B) and the function described here:
https://fits.gsfc.nasa.gov/registry/sip/SIP_distortion_v1_0.pdf
f(u, v) = ∑A_p_q u^p v^q ,
X_corrected = X + f(u,v)
where u and v are relative pixel coordinates with respect to the center of the image.
The same thing goes for the Y-axis too.

I believe the procedure explained above is correct, and once I do that, and run the solve-field afterward (on the undistorted star position) I get an average solving precision of more than one pixel, which is at least 4 time worse than with just regular solving.
If I apply some degree of tweak order in this second solving(after undistiortion is already implemented), the solving precision actually improves. But I think this is wrong, and we should not apply any tweak order after the undistortion is made to the original star positions.
Does anyone have a better understanding of this?

Cheers

 

Dustin Lang

unread,
Jun 15, 2023, 9:33:04 AM6/15/23
to Mark, astrometry
Hi,

Is there any chance you're applying the distortion correction in the wrong direction?  (Ie, doubling the distortion rather than removing it?)

Another thing to try is to run solve-field twice, and on the second run use the --verify option, passing in the WCS solution found in the first round.  This will make it test the solution against all the index files, not just the one it found the answer in.  You can also try using --tweak-order 1, to tune up the solution but not use SIP distortions.

cheers,
dustin


--
You received this message because you are subscribed to the Google Groups "astrometry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astrometry+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/astrometry/6414a880-8158-4a70-98bf-24dbbcddfc24n%40googlegroups.com.

Mark

unread,
Jun 15, 2023, 11:10:02 AM6/15/23
to astrometry
Hi Dustin, thank you for prompt respond.
I am pretty sure I am applying distortion correction in the right direction since when plotting pixel position of the field stars, they are, after distortion correction, plotted closer to the center of the image.
The thing is that by running solve field again, after distortion correction is applied to field stars, astrometry is moving index stars, and by increasing the tweak order, index stars are closer and closer to the position of undistorted field star. So, with second solving, increasing tweak order is improving solution, but to me it does not look like a right thing to do.
Maybe this plot will explain better. This is example for one star, which is located at the top left of the image. corr4 means that field stars are corrected for distortion with SIP coeffs with 4 order.
predistort_one_star.png

Dustin Lang

unread,
Jun 15, 2023, 2:28:23 PM6/15/23
to Mark, astrometry
Hi,

I don't think it's necessarily obvious that the undistorted star positions should be closer to the center of the image.  Distortion could move them in either direction.

I don't really understand what you're plotting.
It seems like there are two WCS file and four pixel coordinates that are relevant:
Let's say your original detected star positions are in orig.xy
Then
    solve-field orig.xy --tweak-order 4 --crpix-center [...]
produces orig.wcs
And then you are un-distorting the coordinates in orig.xy, using orig.wcs, to get undistorted.xy
Then
    solve-field undistorted.xy --tweak-order 1 --crpix-center --rdls index.rd
produces undistorted.wcs
and you can convert index.rd to index-undistorted.xy via
    wcs-rd2xy -w undistorted.wcs -r index.rd -o index-undistorted.xy
and the original index star positions converted to xy, index-orig.xy via
    wcs-rd2xy -w orig.wcs -r index.rd -o index-orig.xy

Then orig.xy and index-orig.xy should be next to each other
And undistorted.xy and index-undistorted.xy should be next to each other.

cheers,
dustin


Mark

unread,
Jun 17, 2023, 6:10:05 AM6/17/23
to astrometry
Hi, I appreciate your help with the explanation.

I understood your steps and I reproduced them.
I just used astropy.all_world2pix() instead of wcs-rd2xy, because it gave me some sort of error.
But the results are the same, and they agree with what you said.

Perhaps my measurements of SIP coefficients are not that good, or maybe they are just within the error. I measured them on a large set of images, removed outliers, and took the mean value. Now I undistort every new image with that fixed SIP coeffs that I found and that I believe correctly represent lens distortion.

And it just happens that when solving undistorted starfield with tweak_order=1, the average distance between the field and index star is 0.4 pixels, but when solving with tweak_order=2, I get a better average distance (accuracy) of 0.2 pixels.

So, my question is: Is it wrong to solve undistorted starfield with tweak_order=2, or should I stick with tw=1(although it gives worse accuracy)?
Which results would you trust more?

Cheers

Dustin Lang

unread,
Jun 17, 2023, 11:45:45 AM6/17/23
to Mark, astrometry
Heh, I don't know, that's a good question :)

In general, any time you give an optimizer another few parameters to tune, it will be able to make the errors smaller.  So I'm not surprised that tweak order 2 (3 extra parameters) is able to reduce the mean error.  You're asking the important question, whether you should believe it or not, and I don't have a good answer for that.  You could imagine there could be some variation between the distortion corrections in different images due to, say, different temperature, or focus, or gravity load if you're pointing in different directions, etc.

cheers,
dustin


Message has been deleted

Mark

unread,
Jul 14, 2023, 8:43:43 AM7/14/23
to astrometry
That makes sense, thank you.
To be 100% sure, for undistorting star position, one should use A and B coefficients and not AP and BP, right?

I will post my code for manually undistorting distorted positions, in case someone needs it, and you Dustin, if it is not too much to ask, could you please just take a look if the procedure is correct?
basically,
undistorted_x = distorted_x + SIP_coefficient * (distorted_x - x_center)
Cheers

Screenshot 2023-07-14 at 14.40.33.png

Dustin Lang

unread,
Jul 14, 2023, 10:03:03 AM7/14/23
to Mark, astrometry
Hi,
I would suggest just making sure your results match, rather than trying to pore over code.  You can either use the astrometry.net code, or the Astropy WCS class, they should both do the same thing.

People get confused about which direction is "distorting" and which is "undistorting".

When you're taking real measured pixel coordinates and converting them to RA,Dec, then you apply what's called the "distortion" direction in the Astrometry.net code, and uses the "A" and "B" coefficients.

cheers,
dustin




Mark

unread,
Jul 17, 2023, 2:59:46 PM7/17/23
to astrometry
Hi,

The code I pasted above is a step before letting astrometry deal with transformation from pixel to RA-Dec and vice-versa.
I want to deal with distortion by hand, which means, to manually correct(undistort) pixel position of a stars. I am doing it by running astrometry --just-augment, then correcting possible sources in .axy file using the code I pasted above, and then finally running astrometry on that "altered" .axy file.

Looking at the sip.c code from the link above, it appears that you are using AP and BP to undistort distorted stars, and I am using A and B. AP and BP gives even worse precision. I will give it some more tought.
Cheers
Reply all
Reply to author
Forward
0 new messages