Author Topic: PixelMath with ImageContainer  (Read 899 times)

Offline Alejandro Tombolini

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1267
    • Próxima Sur
PixelMath with ImageContainer
« on: 2019 July 27 10:58:47 »
Hi,

I have a set of 300 images in a ImageContainer and I would need to apply a PixelMath process that make image1 - image2, image 2 - image3, image n - image n+1
Any help with the formula would be appreciated!  :)

Thank you
Alejandro.

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: PixelMath with ImageContainer
« Reply #1 on: 2019 July 27 11:37:31 »
Hi Alejandro!
Put in the Image Container
the files which you want to use and
put the expression:
image;&count;&extension;
into "Output template:"
this writes your files to the selected output directory as:
image_00001
image_00002

Yes it creates allso these files as views in your workspace but a
"Close All" removes them all.

In PixelMath put your formula and simply  click "Create new image"
and set the Image id to:             image

This is how it works for me.

Gerald

Offline Alejandro Tombolini

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1267
    • Próxima Sur
Re: PixelMath with ImageContainer
« Reply #2 on: 2019 July 27 12:15:04 »
Hi Gerald!!,

In PixelMath put your formula and simply  click "Create new image"
and set the Image id to:             image
Gerald

Which would be the Pixelmath expresion?

I already have all the images in Image container named form image0001 to image0300. What I want to achieve is to subtract image0002 from image0001, then subtract image0003 from image0002, image0004 form image0003 and so on.

Alejandro.

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: PixelMath with ImageContainer
« Reply #3 on: 2019 July 27 13:39:57 »
Usually i use $T and do calculations with the actual image.

I have no idea how to access the last image for calculations with the actual image.
Will think about it but dont see a big chance.

Your request would need a little script which calls PixelMath with the formula and does the job
with actual image and previous image...

Sorry for havin no solution for your specific question.

Gerald

Offline Alejandro Tombolini

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1267
    • Próxima Sur
Re: PixelMath with ImageContainer
« Reply #4 on: 2019 July 27 13:49:28 »

Don't worry Gerald, thank you anyway!!  :)

Saludos, Alejandro.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PixelMath with ImageContainer
« Reply #5 on: 2019 July 30 01:39:35 »
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:

Code: [Select]
#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.


Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Alejandro Tombolini

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1267
    • Próxima Sur
Re: PixelMath with ImageContainer
« Reply #6 on: 2019 August 03 13:57:19 »
Excellent Juan!!, it worked perfectly well. Thank you for your help!

Saludos, Alejandro.