Hi John,
Welcome to PixInsight development. Phew! quite a bunch of questions!
I'll try to answer them as well as I can.
1) Currently I write my script inside script editor (or on my favorite programmer's editor) and then I press F9 on an image. How do I include it in my PI menus ? I saved mine in the same directory as all the others, used #feature-id and #feature-info and tried to "Regenerate" "Feature Scripts", but still I can not see it in the menu.
Regenerate is not sufficient. You must click the Add button to effectively add your script to the list of featured scripts.
2) How do I put a "New Instance" triangle and a "Apply (F5)" rectangle on my dialog? I see that many scripts specify with drop-down lists on which image(s) they should apply, but is there a way a PJSR script to follow the same elegant triangle/rectangle schema ?
Take a look at the DrawSignature script and study the DrawSignatureEngine object carefully. In the DrawSignatureEngine.initialize() method you can see how the Parameters PJSR object is used to retrieve a set of parameters that the script uses (text, fontFace, fontSize, etc.). The following method of Parameters:
Boolean Parameters.has( String id )returns true when the specified parameter
id is currently defined as a script parameter. The family of methods:
Boolean Parameters.getBoolean( String id )
Number Parameters.getInteger( String id[, int radix=0] )
Number Parameters.getReal( String id )
String Parameters.getString( String id )
Number Parameters.getUInt( String id[, int radix=0] )Return the value of a parameter
id of the specified data types. Note that type conversions are performed automatically by the PJSR. For security reasons, all script parameters are stored as objects of type String. This prevents injections of malicious JavaScript code through script parameters. The automatic conversion implies that a script parameter whose value is "1.234" can be obtained as both String and Number; however, "1+2" can only be String,
never Number.
Boolean Parameters.isViewTargetis true when the script is being executed in the
view context. For example, this happens when a Script icon is dropped on an image. In such case:
View Parameters.targetViewis a reference to the view where the script is being executed. Complementarily:
Boolean Parameters.isGlobalTargetis true when the script is being executed in the
global context. For example, this happens when a script is executed directly from the Script menu, or from the Process Explorer window.
Finally, take a look at the DrawSignatureEngine.exportParameters() method and how it is used to export a set of script parameters. Exported parameters will be available (via has()/get()) in a subsequent execution. To export a parameter from a script, the following method is used:
void Parameters.set( String id, Object value )where
id is the parameter identifier and
value is the parameter value.
As for the blue triangle icon (thanks for the
elegant adjective
), it is quite easy, too. In DrawSignature.js, go to line # 619 and see how the newInstance_Button is created and managed. The newInstance_Button.onMousePress() event handler exports the script parameters (by calling exportParameters()) and initiates an interactive dragging procedure by calling Dialog.newInstance(). Everything else (the drag & drop procedure, icon creation, etc.) happens in an automatic fashion.
3) Let say that I modify an image using beginProcess(); / endProcess(); . How do I specify a more descriptive name so that the history browser shows this name and not just "Script" ?
You can't. Scripts are always encapsulated as Script instances. A Script instance knows where's the script source code and keeps a cryptographic digest of the executed source code, which is part of PJSR's security scheme. In a future version, Script instances will borrow their icons from the #feature-icon directive, if it exists, but this has not been implemented yet.
4) Let me see if I got this right, if I want to use an external object on an image (eg HistogramTransformation) , I create a new instance of it and then I use the executeOn ( view ) method, right ?
Correct. In PixInsight's object oriented model, process instances are executed on views, not the opposite.
5) and in the above case I DO NOT use beginProcess(); / endProcess(); right ?
Right. The beginProcess()/endProcess() protocol isn't necessary when you execute a process instance, because it is already part of the instance execution procedure.
6) How do I use Image.FFT, or as the matter of fact, any other FFT method, to produce the FFT (or the reverse) of an image ? It replies that it requires a complex number Huh? ? I lack the theoretical background on this, but I thought that FFT is something that you can just pop from any image (based on ImageJ's equivelant function)
The Fourier transform operates on complex images. In a complex image, each pixel is a complex number with a real and an imaginary part. Complex images cannot be manipulated directly in the GUI, but only through the development frameworks (PJSR and PCL). To obtain the FT of a real image, you first have to convert it to a complex image. The following routine can be helpful in this case:
//
// Returns the discrete Fourier transform (DFT) of the current rectangular
// selection of the specified image.
//
// If the centered argument is specified and is true, then the computed DFT
// will be symmetric with respect to the center of the transformation matrix:
// The central pixel of the DFT will correspond to the DC component of the
// transform (zero frequency), and the frequencies in the transform will grow
// radially from the central point.
//
// The returned DFT is a complex image with optimized dimensions. Note that the
// DFT can be larger than the original image selection.
//
this.fft = function ( image, centered )
{
var C = Image.newComplexImage();
C.allocate( image.selectedRect.width, image.selectedRect.height );
C.apply( image );
C.FFT( centered );
return C;
};
Good luck and enjoy!