Author Topic: Tips for first script  (Read 4812 times)

Offline Yarosia

  • Newcomer
  • Posts: 12
    • Astrobin
Tips for first script
« on: 2015 August 25 07:33:09 »
Hi!
I would like to write a script that allows the user to:

Apply a pixelmath function with 2 parameters as input (the parameters are CFA channel to elaborate (0,1,2,3) and a multiplicative factor).
Based on the CFA channel i will select the right function and apply to the image (with odd or even coords i can touch the right pixel)

I can't find much documentation, and i have Java and C# (and Android programming aswell) knowledge.
Should'nt be that hard i think. Is there any script i can take as newbie reference?

Thank you very much!

Offline mschuster

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1087
Re: Tips for first script
« Reply #1 on: 2015 August 25 09:24:24 »
View > Explorer Windows > Object Explorer for a list of scriptable objects and processes and their properties and methods.

View > Script Editor to create, edit, save, and execute your .js script file.

Here is sample code to try. You'll want to edit the viewId, the channel (a number from 0 to 3), and the factor.

The expression encodes pixel position as a channel number and uses a conditional to either apply the factor or not.

This should give you something to start with. Adding a user interface is a bit more work.

Use PI's "Undo" icon or ^Z to undo the script's operation on the view.

Mike

Code: [Select]
// CFAApply.js

// Parameters
var viewId = "frame_001";
var channel = 1;
var factor = 2;

// Expressions and view
var expression = "iif((xpos() % 2) + 2 * (ypos() % 2) == channel, factor * $target, $target)";
var symbols = format("channel = %d, factor = %f", channel, factor);
var view = View.viewById(viewId);

// Evaluation
var pixelMath = new PixelMath;
pixelMath.expression = expression;
pixelMath.symbols = symbols;
pixelMath.executeOn(view, true);


Offline Yarosia

  • Newcomer
  • Posts: 12
    • Astrobin
Re: Tips for first script
« Reply #2 on: 2015 August 25 09:29:42 »
Thank you very much!
Now i have something to start with!  ^-^
[EDIT]
i found i was using a more complex pixelmath function... thanks for this too! ;)
« Last Edit: 2015 August 25 09:35:57 by Yarosia »