// JavaScript source code


function registerImages() {
    /*
     * Register images and combine channels to produce LRGB and LRGB images - the
     * idea is the user will have an interface that specifies a naming convention
     * for the channels (L, R, G and B or L, RGB) and the script generator
     * program will auto-generate the code specifying file paths
     * (easy to do with C#, for example)
     */
    var imageReg = new StarAlignment;
    imageReg.structureLayers = 5;
    imageReg.noiseLayers = 0;
    imageReg.hotPixelFilterRadius = 1;
    imageReg.noiseReductionFilterRadius = 0;
    imageReg.sensitivity = 0.100;
    imageReg.peakResponse = 0.80;
    imageReg.maxStarDistortion = 0.500;
    imageReg.upperLimit = 1.000;
    imageReg.invert = false;
    imageReg.distortionModel = "";
    imageReg.undistortedReference = false;
    imageReg.distortionCorrection = false;
    imageReg.distortionMaxIterations = 20;
    imageReg.distortionTolerance = 0.005;
    imageReg.matcherTolerance = 0.0500;
    imageReg.ransacTolerance = 2.00;
    imageReg.ransacMaxIterations = 2000;
    imageReg.ransacMaximizeInliers = 1.00;
    imageReg.ransacMaximizeOverlapping = 1.00;
    imageReg.ransacMaximizeRegularity = 1.00;
    imageReg.ransacMinimizeError = 1.00;
    imageReg.maxStars = 0;
    imageReg.useTriangles = REPLACE_WITH_USE_TRIANGLES;
    imageReg.polygonSides = 5;
    imageReg.descriptorsPerStar = 20;
    imageReg.restrictToPreviews = true;
    imageReg.intersection = StarAlignment.prototype.MosaicOnly;
    imageReg.useBrightnessRelations = false;
    imageReg.useScaleDifferences = false;
    imageReg.scaleTolerance = 0.100;
    imageReg.referenceImage = "REPLACE_WITH_PATH_TO_REFERENCE_IMAGE";
    imageReg.referenceIsFile = true;
    imageReg.targets = REPLACE_WITH_TARGETS;
    imageReg.inputHints = "";
    imageReg.outputHints = "";
    imageReg.mode = StarAlignment.prototype.RegisterMatch;
    imageReg.writeKeywords = true;
    imageReg.generateMasks = false;
    imageReg.generateDrizzleData = false;
    imageReg.frameAdaptation = false;
    imageReg.noGUIMessages = true;
    imageReg.useSurfaceSplines = false;
    imageReg.splineSmoothness = 0.25;
    imageReg.pixelInterpolation = StarAlignment.prototype.Auto;
    imageReg.clampingThreshold = 0.30;
    imageReg.outputDirectory = "REPLACE_WITH_PATH_TO_OUTPUT_DIRECTORY";
    imageReg.outputExtension = ".fit";
    imageReg.outputPrefix = "";
    imageReg.outputPostfix = "_r";
    imageReg.maskPostfix = "_m";

    imageReg.outputSampleFormat = StarAlignment.prototype.SameAsTarget;
    // Optional, force saving as 16-bit..
    // But PixInsight clobbers the low-end values as it scales the peak values to 65k
    // So if you have really high peak values (e.g., 97k), then the low values are lost.
    // In comparison, RegiStar simply truncates the float values to integer, no scaling.
    //imageReg.outputSampleFormat = StarAlignment.prototype.i16;

    imageReg.overwriteExistingFiles = false;
    imageReg.onError = StarAlignment.prototype.Continue;
    imageReg.useFileThreads = true;
    imageReg.fileThreadOverload = 1.20;
    imageReg.maxFileReadThreads = 1;
    imageReg.maxFileWriteThreads = 1;
    imageReg.executeGlobal();
}

function main()
{
    registerImages();

}

main();



