Author Topic: Bug in StarAligment using a file as reference  (Read 7119 times)

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Bug in StarAligment using a file as reference
« on: 2012 June 14 07:01:13 »
I have found a problem in StarAligment when the reference is a file with the location of the stars. After several tests I think that the matrix returned by StarAlignment has a displacement of 0.5 pixels.

I have made a test case composed by an image, a file with the location of the stars and a little script for aligning the image to the file. The coordinates of the stars are very similar to the coordinates returned by DynamicPSF. Since the image and the file have the stars in the same position, the matrix generated by StarAligment should be the identity matrix. However, the result of the script has an offset of 0.5 pixels.

The test case can be downloaded from this url: https://dl.dropbox.com/u/71653208/ProblemaStarAlignment.7z


Processing script file: ./test1.js

StarAlignment: Processing view: stars2
./stars.csv:
Scanning star data: done.
116 stars.
stars2:
Structure map: 100%
Detecting stars: 100%
915 stars found.
Matching stars ...
115 putative star pair matches.
Performing RANSAC ...
110 star pair matches in 66 RANSAC iterations.
Summary of model properties:
Inliers     : 0.957
Overlapping : 0.994
Regularity  : 0.941
Quality     : 0.945
Root mean square error:
?RMS  :  0.222 px
Average RMS error deviation:
?RMS  :  0.180 px
Peak errors:
?xmax :  0.804 px
?ymax :  1.510 px
Transformation matrix:
     +1.0000     +0.0000     -0.5165
     -0.0000     +1.0000     -0.5091
     -0.0000     +0.0000     +1.0000
scale    : 1.000
rotation :     +0.00°
dx       :     -0.52 px
dy       :     -0.51 px
3.036 s



Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Bug in StarAligment using a file as reference
« Reply #1 on: 2012 June 14 08:52:49 »
Hi Andrés,

Bug confirmed. Thank you for detecting this problem (and sorry for not having answered your messages before).

I have already found and fixed this bug in StarAlignment. The problem is with SA's star detection routine, not with coordinates read from CSV files. This is potentially problematic. I wonder if once I publish a new StarAlignment tool with this bug fixed, the fix will have an impact on your ImageSolver script. The consequence of fixing this bug is that SA will refer all of its computed star positions on images (not from CSV files) to (0,0). Previously (that is, now), all star positions were actually referred to (-0.5,-0.5).

Right now I am working on a high-level parallelization of this process, which is a very complex task. Since this is not a very critical bug for normal users, I'll wait until I have all the work done and tested before releasing a new version of the ImageRegistration module.

For now, the workaround is simple: subtract 0.5 from the X and Y coordinates of CSV files in your script. This may require generating a temporary file to feed SA. Sorry for the inconvenience.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: Bug in StarAligment using a file as reference
« Reply #2 on: 2012 June 14 09:09:09 »
Thanks Juan,

because of this bug ImageSolver returns coordinates with an error of half a pixel. I detected this problem when working on the Photometry script, but I think this is also the root of the problem reported by Mike Schuster in this message: http://pixinsight.com/forum/index.php?topic=3966.msg30401#msg30401.

Knowing that you are working on it, I won't modify ImageSolver for adding the temporal hack.

Hi Andrés,

Bug confirmed. Thank you for detecting this problem (and sorry for not having answered your messages before).

I have already found and fixed this bug in StarAlignment. The problem is with SA's star detection routine, not with coordinates read from CSV files. This is potentially problematic. I wonder if once I publish a new StarAlignment tool with this bug fixed, the fix will have an impact on your ImageSolver script. The consequence of fixing this bug is that SA will refer all of its computed star positions on images (not from CSV files) to (0,0). Previously (that is, now), all star positions were actually referred to (-0.5,-0.5).

Right now I am working on a high-level parallelization of this process, which is a very complex task. Since this is not a very critical bug for normal users, I'll wait until I have all the work done and tested before releasing a new version of the ImageRegistration module.

For now, the workaround is simple: subtract 0.5 from the X and Y coordinates of CSV files in your script. This may require generating a temporary file to feed SA. Sorry for the inconvenience.

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
[1.8] Bug in StarAligment using a file as reference
« Reply #3 on: 2013 January 02 02:33:03 »
This bug is still not resolved in the version 1.8RC1

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Bug in StarAligment using a file as reference
« Reply #4 on: 2013 January 02 12:04:43 »
Hi Andrés,

I am sorry, I should have answered this post before. This is actually not a bug, but a feature of SA, so it won't be "fixed".

The problem here is in the origin of coordinates used by SA to refer star positions. Let's consider each pixel as a square of fixed dimensions. SA's star detection routine works under the assumption that the origin of coordinates is at the center of the pixel located at the upper left corner of the image. Y coordinates grow from top to bottom and X coordinates grow from left to right. Unfortunately, this origin is different from the origin used by the rest of the platform, where coordinates are measured from the top left corner of the top left pixel. However, it is necessary for SA in order to support specular transformations---as the ability to automatically correct for meridian flips---, so it can't be changed without introducing significant (and ugly) hacks in the whole SA process.

Of course, a suitable solution to this problem must be found. The solution that I have designed consists of adding two new floating point parameters to the StarAlignment process: inputOffsetX and inputOffsetY. The values of these parameters will be added to the reference X and Y coordinates, respectively, when the reference positions come from a CSV file. The default values will be zero. In your script, you'll just have to assign -0.5 to both parameters in order to adapt your positional data to SA's internal coordinate system.

Let me know if this solution is valid for you. These new parameters will be available in the next release of the ImageRegistration module. I can have it ready in a couple days.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: Bug in StarAligment using a file as reference
« Reply #5 on: 2013 January 02 12:26:11 »
Thanks Juan.

I think that it is not necessary to add those two new properties. Knowing that SA uses the center of the pixels as the reference for the coordinates is enough.

I can fix the values returned by SA by myself. I have only to translate by (-0.5,-0.5) the returned matrix. When I reported this "bug/feature"  ;) I tested this and it works perfectly. I didn't published the fixed version because you said that you were to change it in the next version.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Bug in StarAligment using a file as reference
« Reply #6 on: 2013 January 02 12:39:32 »
Quote
you said that you were to change it in the next version

That's true, and I apologize for that. When I analyzed the problem in more detail I realized it was just a matter of different coordinate origins. I think that the two new parameters would make SA more flexible for scripting, so I'll probably add them anyway.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: Bug in StarAligment using a file as reference
« Reply #7 on: 2013 January 02 12:50:59 »
Ok.
I won't do anything until you add these properties.

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: Bug in StarAligment using a file as reference
« Reply #8 on: 2013 January 02 15:39:16 »
Quote
just a matter of different coordinate origins

That was my conclusion also when I wrote ImageLabeler. It was easy to account for the 0.5 x/y offset in a transformation matrix.

Mike

Edit: Basically I changed the 0.5 constants in this matrix to 0.0 (in your file WCSmetadata.jsh) and removed the equivalent "adjustment" from some other part of the code:

            var ref_F_I = new Matrix(
                     1,0,0.5,
                     0,-1,this.height+0.5,
                     0,0,1
                  );
« Last Edit: 2013 January 02 16:01:38 by mschuster »

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: Bug in StarAligment using a file as reference
« Reply #9 on: 2013 January 20 02:32:36 »

Edit: Basically I changed the 0.5 constants in this matrix to 0.0 (in your file WCSmetadata.jsh) and removed the equivalent "adjustment" from some other part of the code:

            var ref_F_I = new Matrix(
                     1,0,0.5,
                     0,-1,this.height+0.5,
                     0,0,1
                  );

Hi Mike.
I have reread your message and I think that the code for ref_F_I in WCSmetadata is correct. That matrix converts the coordinates from WCS convention (the coordinates of the center of the lower-left pixel are [1,1]) to the convention of PI. You can read the first paragraph from the section 2.1.4 of "Representations of world coordinates in FITS".
The error should be corrected when the WCS matrix is generated from the result of StarAlignment.