Author Topic: Substitute with Preview  (Read 12837 times)

Offline Silvercup

  • PixInsight Addict
  • ***
  • Posts: 187
Substitute with Preview
« on: 2010 March 16 17:00:28 »
Hola a todos:

Quiero compartir este stript: Substitute with Preview. El objetivo principal del Script es crear mascaras de estrellas con estrellas de diferente tamaño. Si en una imagen tenemos estrellas pequeñas y algunas grandes, si construimos una máscara para las estrellas pequeñas no suele protejer bien las grandes y viceversa.

En este ejemplo se puede ver mejor. He creado dos starmask la primera con un GROW de 0 y las segunda con un GROW de 2, después selecciono mediante previews en la máscara segunda, las estrellas que no estan protegidas con la primera máscara y ejecuto el script y obtengo una imagen final con los previews sustituidos.





Hello everyone,

I want to share this script: Substitute with Preview. The main purpose of this script is to create starmask  with stars of different sizes. If an image has small stars and some big stars, if we build a mask for the small stars do not usually protect well the great ones and vice versa.

In this example you can see better. I have created two starmask the first with GROW 0 and the second one with GROW 2, then several previews have been selected in the second mask with the stars not properly protected by the first mask. When we run the script, we get a final image with the previews replaced.

See above image.


Saludos. Gretings. Silvercup

Code: [Select]
#include <pjsr/Sizer.jsh>
#include <pjsr/FrameStyle.jsh>
#include <pjsr/TextAlign.jsh>
#include <pjsr/StdButton.jsh>
#include <pjsr/StdIcon.jsh>
#include <pjsr/StdCursor.jsh>
#include <pjsr/UndoFlag.jsh>
#include <pjsr/SampleType.jsh>
#include <pjsr/ColorSpace.jsh>

#define VERSION "1.00"
#define TITLE "Substitute with Preview"

function SubstitutePreviewData()
{
   this.sourceView = ImageWindow.activeWindow.mainView;
   this.targetView = ImageWindow.activeWindow.mainView;
}

var data = new SubstitutePreviewData;

function SubstitutePreviewDialog()
{
   this.__base__ = Dialog;
   this.__base__();

   var labelWidth1 = 100;

   //

   this.helpLabel = new Label( this );
   with ( this.helpLabel )
   {
      frameStyle = FrameStyle_Box;
      margin = 4;
      wordWrapping = true;
      useRichText = true;
      text = "<p><b>" + TITLE + " v" + VERSION + "</b> &mdash; A script for preview substitution.</p>";
   }


   this.sourceImage_Label = new Label( this );
   with ( this.sourceImage_Label )
   {
      minWidth = labelWidth1 + 6+1; // align with labels inside group boxes below
      text = "Source image:";
      textAlignment = TextAlign_Right|TextAlign_VertCenter;
   }

   this.sourceImage_ViewList = new ViewList( this );
   with ( this.sourceImage_ViewList )
   {
      minWidth = 200;
      getMainViews(); // include main views
      currentView = data.sourceView;
      toolTip = "Select the source image with preview.";
      onViewSelected = function( view )
      {
         data.sourceView = view;
      };
   }

   this.sourceImage_Sizer = new HorizontalSizer;
   with ( this.sourceImage_Sizer )
   {
      spacing = 4;
      add( this.sourceImage_Label );
      add( this.sourceImage_ViewList, 100 );
   }






   this.targetImage_Label = new Label( this );
   with ( this.targetImage_Label )
   {
      minWidth = labelWidth1 + 6+1; // align with labels inside group boxes below
      text = "Target image:";
      textAlignment = TextAlign_Right|TextAlign_VertCenter;
   }

   this.targetImage_ViewList = new ViewList( this );
   with ( this.targetImage_ViewList )
   {
      minWidth = 200;
      getMainViews(); // include main views
      currentView = data.targetView;
      toolTip = "Select the target image to substitute with preview.";
      onViewSelected = function( view )
      {
         data.targetView = view;
      };
   }

   this.targetImage_Sizer = new HorizontalSizer;
   with ( this.targetImage_Sizer )
   {
      spacing = 4;
      add( this.targetImage_Label );
      add( this.targetImage_ViewList, 100 );
   }



   this.ok_Button = new PushButton (this);
   with ( this.ok_Button )
   {
      text = "OK";

      // Do it
      onClick = function() {

   if ( data.sourceView.window.previews.length == 0 )
   {

      var msg = new MessageBox( "Source image has no previews. Select a source image with previews.",
                                "Substitute with Preview Script", StdIcon_Error, StdButton_Ok );
      msg.execute();
      return;
   }else{

     

      var finalView= new ImageWindow(data.targetView.image.width,
                                 data.targetView.image.height,
                                 data.targetView.image.numberOfChannels,
                                 data.targetView.window.bitsPerSample,
                                 data.targetView.window.isFloatSample,
                                 data.targetView.image.colorSpace != ColorSpace_Gray,
                                 "FinalView");

      finalView.mainView.beginProcess(UndoFlag_NoSwapFile);
      finalView.mainView.image.assign( data.targetView.image );
      finalView.mainView.endProcess();

      var previews = data.sourceView.window.previews;

      for ( var i = 0; i < previews.length; ++i )
      {
      var fullViewpoints = data.sourceView.window.previewRect(previews[i]);
      finalView.mainView.beginProcess(UndoFlag_NoSwapFile);
      finalView.mainView.image.selectedPoint = new Point(fullViewpoints.x0,fullViewpoints.y0);
      finalView.mainView.image.apply(previews[i].image);
      finalView.mainView.endProcess();
      finalView.show();
      };

      this.dialog.ok();

      }
   }
   }

   this.cancel_Button = new PushButton (this);
   with ( this.cancel_Button )
   {
      text = "Cancel";

      onClick = function() {
         this.dialog.cancel();
      };
   }

   this.buttons_Sizer = new HorizontalSizer;
   with ( this.buttons_Sizer )
   {
      spacing = 4;
      add( this.cancel_Button );
      add( this.ok_Button );
   }


 this.sizer = new VerticalSizer;
   with ( this.sizer )
   {
      margin = 6;
      spacing = 2;
      addStretch();
      add ( this.helpLabel );
      addSpacing (4);
      add( this.sourceImage_Sizer );
      add( this.targetImage_Sizer );
      addSpacing (4);
      add ( this.buttons_Sizer );
   }



}

SubstitutePreviewDialog.prototype = new Dialog;

function main()
{
   console.hide();

   if ( data.sourceView.isNull )
   {
      var msg = new MessageBox( "There is no active image window!",
                                "Substitute with Preview Script", StdIcon_Error, StdButton_Ok );
      msg.execute();
      return;
   }
   

   var dialog = new SubstitutePreviewDialog();
   dialog.execute();

}

main();

Offline Simon Hicks

  • PixInsight Old Hand
  • ****
  • Posts: 333
Re: Substitute with Preview
« Reply #1 on: 2010 March 17 09:22:34 »
Silvercup,

That looks like a very good script with a wide range of uses. You could do one deconvolution optimised for 90% of the stars, and then do a different optimised deconvolution for the 5 large stars in the image...and then swap then across. There are other ways to do this, but they all get messy and tricky....this might simplify things. I'm sure there will be lots of other uses.

Cheers
         Simon

Offline avastro

  • PixInsight Addict
  • ***
  • Posts: 181
    • http://astrosurf.com/avastro/
Re: Substitute with Preview
« Reply #2 on: 2010 March 18 02:56:06 »
Hola Silvercup,
I tested your script and got this error message:
Processing script file: C:/PCL/src/scripts/starmakagregate.js
*** Error [001]: C:/PCL/src/scripts/starmakagregate.js, line 29: ReferenceError: FrameStyle_Box is not defined
I'm probably doing something wrong  :(

Cheers

Antoine
Antoine
Lentin Observatory
http://www.astrosurf.com/avastro/

Offline mmirot

  • PixInsight Padawan
  • ****
  • Posts: 881
Re: Substitute with Preview
« Reply #3 on: 2010 March 18 13:38:52 »
Killer idea.

Max

Offline Silvercup

  • PixInsight Addict
  • ***
  • Posts: 187
Re: Substitute with Preview
« Reply #4 on: 2010 March 18 14:18:06 »
Hi Antoine:

It seems you haven't copy all script. You have forgotten this Line #include <pjsr/FrameStyle.jsh> or you missed FrameStyle.jsh library.


Best. Silvercup

Offline avastro

  • PixInsight Addict
  • ***
  • Posts: 181
    • http://astrosurf.com/avastro/
Re: Substitute with Preview
« Reply #5 on: 2010 March 19 00:34:42 »
Hola Silvercup,
You was right, my error  :(
Your script is very useful, thanks again

Cheers
Antoine
Antoine
Lentin Observatory
http://www.astrosurf.com/avastro/

Offline sleshin

  • PixInsight Old Hand
  • ****
  • Posts: 431
Re: Substitute with Preview
« Reply #6 on: 2010 March 19 17:00:20 »
Hi Silvercup,

Want to try your script but unable to get it to load into PI. I copied and pasted the script into Notepad and then saved it as a .js file When I try to Add it to PI  in the Feature Scripts dialog I get a message that "0 additional featured script(s) were found on directory". I have successfully added other scripts so I'm not sure what's going wrong. Any help/suggestions appreciated.

Steve
Steve Leshin

Stargazer Observatory
Sedona, Arizona

Offline avastro

  • PixInsight Addict
  • ***
  • Posts: 181
    • http://astrosurf.com/avastro/
Re: Substitute with Preview
« Reply #7 on: 2010 March 20 03:33:29 »
Hi Steve
Try to copy the script directly in PI script editor in the left side of PI window.
Click in it, then File -> new ->Javascriptsource file or ctrl+N then paste the script-> Execute -> compile & run or F9. You will save it in a folder, point the Feature Scripts dialog to this folder and add it to PI.
That  work fine for me.

Cheers

Antoine
Antoine
Lentin Observatory
http://www.astrosurf.com/avastro/

Offline sleshin

  • PixInsight Old Hand
  • ****
  • Posts: 431
Re: Substitute with Preview
« Reply #8 on: 2010 March 20 13:53:33 »
Hi Antoine,

Thanks for responding. I followed your suggestions. Copied the script into the Script Editor, compiled it and saved it to a folder. But still could not add it to PI using Add in the Feature Scripts dialog. PI doesn't see this.fs file for some reason. On the other hand, with the script copied into the script editor, it does run. So, if I want to use it I'd have to recopy it into PI each time. I do have the script copied in a .js file so manually opening it is not a problem, just a nuisance. :(

Any other thoughts?

Steve
Steve Leshin

Stargazer Observatory
Sedona, Arizona

Offline Silvercup

  • PixInsight Addict
  • ***
  • Posts: 187
Re: Substitute with Preview
« Reply #9 on: 2010 March 20 16:11:44 »
Hi Steve:

You must add this lines:

Code: [Select]

#feature-id Utilities > SubstitutewithPreview
#feature-info A simple script for Previews substitution.<br><br/>\
   <br/>\
   Copyright &copy; 2010 Juan M. Gómez


But the script isn't part of PI platform officialy, so, as usual, I don't put those lines.

Greetings, Silvercup

Offline sleshin

  • PixInsight Old Hand
  • ****
  • Posts: 431
Re: Substitute with Preview
« Reply #10 on: 2010 March 20 16:46:46 »
Thanks Silvercup, that took care of it.

Steve
Steve Leshin

Stargazer Observatory
Sedona, Arizona

Offline Jordi Gallego

  • PixInsight Addict
  • ***
  • Posts: 279
Re: Substitute with Preview
« Reply #11 on: 2010 March 21 13:10:19 »
Hi Silvercup, thanks for this new script ;)

Regards
Jordi
Jordi Gallego
www.astrophoto.es

Offline mmirot

  • PixInsight Padawan
  • ****
  • Posts: 881
Re: Substitute with Preview
« Reply #12 on: 2010 March 21 13:42:28 »
Maybe Juan could add this to PI 1.60 or 1.61.

Max

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Substitute with Preview
« Reply #13 on: 2010 March 21 14:19:14 »
Maybe Juan could add this to PI 1.60 or 1.61.

Indeed. If Silver doesn't tell otherwise, I'll add this little but useful script to 1.6. So feel free to add the #feature macros to the script's source code ;) Nice work!
Juan Conejero
PixInsight Development Team
http://pixinsight.com/