Author Topic: Star detection  (Read 168 times)

Offline janez skubic

  • Newcomer
  • Posts: 2
    • View Profile
Star detection
« on: 2019 March 16 06:01:28 »
Is there a way to get the list of detected stars (positions in the image, star intensity) as text file from StarDetection algorithm used in StarAlignment?
Maybe there are other easier ways?
/Janez Skubic

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 6578
    • View Profile
Re: Star detection
« Reply #1 on: 2019 March 17 03:04:33 »
You'll have to use JavaScript to do this. The StarDetector object is the best option. To get a first grasp of this object, here is an example that will create a mask with all stars detected on the current image:

Code: [Select]
#include <pjsr/StarDetector.jsh>

var S = new StarDetector;
S.test( ImageWindow.activeWindow.mainView.image, true/*createStarmask*/ );

Activate the generated mask on the image and inspect it. You'll see a circle drawn centered on each detected star.

A more interesting example:

Code: [Select]
#include <pjsr/StarDetector.jsh>

var S = new StarDetector;
var stars = S.stars( ImageWindow.activeWindow.mainView.image );
var f = File.createFileForWriting( "/tmp/stars.txt" );
for ( let i = 0; i < stars.length; ++i )
   f.outTextLn( format( "%5d %8.2f %8.2f %8.3f", i, stars[i].pos.x, stars[i].pos.y, stars[i].flux ) );

This example will create a new text file where each line corresponds to a detected star. The columns are: star index, X coordinate, Y coordinate, and star flux (accumulated pixel data on the star detection region). Obviously, star detection works best on linear images.

You can also use the StarAlignment process, although it doesn't provide information on star fluxes. The StarAlignment.outputData property contains relevant data for all stars used for alignment after a successful execution of the StarAlignment process. Here is a schematic example:

Code: [Select]
#define REFERENCE_X              29
#define REFERENCE_Y              30
#define TARGET_X                 31
#define TARGET_Y                 32

   let SA = new StarAlignment;
   if ( SA.executeOn( view ) )
      let stars = [];
      let n = SA.outputData[0][NUMBER_OF_PAIR_MATCHES];
      for ( let i = 0; i < n; ++i )
         stars.push( { refX:SA.outputData[0][REFERENCE_X][i],
                       tgtY:SA.outputData[0][TARGET_Y][i] } );

This would create an array of objects, where refX,refY are the image coordinates of a reference star and tgtX,tgtY are the corresponding coordinates of the same star matched on the target image (the image in the 'view' object in the example above). Coordinates are in pixels, where 0,0 is the top left corner of the pixel at the top left corner of the image. As noted before, StarAlignment does not provide star fluxes.

Let me know if this helps.

Juan Conejero
PixInsight Development Team

Offline janez skubic

  • Newcomer
  • Posts: 2
    • View Profile
Re: Star detection
« Reply #2 on: 2019 March 17 08:05:42 »
Thank you! This will do it for my current purposes.
« Last Edit: 2019 March 21 08:46:39 by janez skubic »