Hi Alejandro,
These tasks can be implemented very easily as scripts. What you are describing is beyond the scope of the PixelMath process.
Here is a small script (34 lines) that does exactly what you want:
#include <pjsr/ImageOp.jsh>
#include <pjsr/UndoFlag.jsh>
function SubtractSuccessiveImages( inputTemplate, outputDir )
{
let inputFiles = searchDirectory( inputTemplate );
inputFiles.sort();
for ( let i = 0; i < inputFiles.length-1; ++i )
{
let thisWindow = ImageWindow.open( inputFiles[i] )[0];
let nextWindow = ImageWindow.open( inputFiles[i+1] )[0];
let thisView = thisWindow.mainView;
let nextView = nextWindow.mainView;
thisView.beginProcess( UndoFlag_NoSwapFile );
thisView.image.apply( nextView.image, ImageOp_Sub );
thisView.endProcess();
let outputFilePath = outputDir + format( "/%03d-%03d.xisf", i+1, i+2 );
if ( !thisWindow.saveAs( outputFilePath,
false/*queryOptions*/,
false/*allowMessages*/,
true/*strict*/,
false/*verifyOverwrite*/ ) )
{
console.criticalln( "*** Error: Failure to write output image: ", outputFilePath );
break;
}
thisWindow.forceClose();
}
}
SubtractSuccessiveImages( "/Users/juan/test/*.xisf", "/Users/juan/test/output" );
The script performs subtractions between successive pairs of images, which it finds on a specified input directory. The results are written to a specified output directory. The script assumes that the order of images corresponds to the list of image file names sorted alphabetically in ascending order. I think the script is quite self-describing; let me know if you need further help to understand how it works.
PixInsight is a scriptable environment precisely to solve this kind of problems.