Author Topic: Med() function question  (Read 3536 times)

Offline StasV

  • Newcomer
  • Posts: 29
Med() function question
« on: 2011 March 28 22:06:59 »
As I understand, med() function is able to work with a single image only.
Is it possible in PixelMath to calculate a median value of the sum of two images?
FSQ106ED, ASA DDM60 mount, STL11k,  HomeDome HD6
Remote control observatory, San Pedro De Atacama, Chile. In collaboration with Yuri Beletsky

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Med() function question
« Reply #1 on: 2011 March 29 02:08:51 »
PixelMath is a pixel-by-pixel process. The med(image) function returns the median of the specified image ($T by default), which remains invariant during PixelMath execution.

To compute the median of the sum of two or more images you need a script. Such a script is rather easy to write though:

Code: [Select]
#include <pjsr/ImageOp.jsh>
#include <pjsr/StdButton.jsh>

function MedianOfTwoAdded( img1, img2 )
{
   var imgs = new Image;
   imgs.assign( img1 );
   imgs.apply( img2, ImageOp_Add );
   var m = imgs.median();
   imgs.free();
   return m;
}

function main()
{
   var vA = View.viewById( "A" );
   var vB = View.viewById( "B" );

   if ( vA.isNull || vB.isNull )
   {
      (new MessageBox( "Source image(s) not available.",
                       TITLE, StdIcon_Error, StdButton_Ok )).execute();
      return;
   }

   console.writeln( format( "%.6f\n", MedianOfTwoAdded( vA.image, vB.image ) ) );
   console.show();
}

main();

Just replace "A" and "B" with the identifiers of your images (or rename your images to "A" and "B"), and run the script. If more than a few images are required, the above script is easily generalizable to image lists of arbitrary length using arrays.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: Med() function question
« Reply #2 on: 2011 March 29 08:33:36 »
Suggestion: you may expand PM by enabling calcularions inside functions ;) then, it may be possible to run Med(A+B)
Regards,

Carlos Milovic F.
--------------------------------
PixInsight Project Developer
http://www.pixinsight.com

Offline vicent_peris

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 988
    • http://www.astrofoto.es/
Re: Med() function question
« Reply #3 on: 2011 March 29 12:40:00 »
Suggestion: you may expand PM by enabling calcularions inside functions ;) then, it may be possible to run Med(A+B)

Or release a Calculator.


V.

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: Med() function question
« Reply #4 on: 2011 March 29 14:13:28 »
Pixel Math? :D
Regards,

Carlos Milovic F.
--------------------------------
PixInsight Project Developer
http://www.pixinsight.com