Author Topic: PJSR: Drawing Image into Graphics with STF  (Read 5234 times)

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
PJSR: Drawing Image into Graphics with STF
« on: 2009 July 22 15:18:49 »
Juan,

I have an image that I would like to render with STF into a Graphics object that is part of a ScrollBox. Without STF, it works this way:
Code: [Select]
      var g = new Graphics( this );
      var result=this.parent.getImage();
      g.drawBitmap( this.parent.scrollPosition.symmetric(), result.render() );
      g.end();

How can I include the STF of a view into this process? Maybe it is simple and I just don't see the right call() at this moment.

Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: PJSR: Drawing Image into Graphics with STF
« Reply #1 on: 2009 July 23 10:46:27 »
Hi Georg,

A STF is a collection of histogram transformations. The easiest (and fastest) way to apply it is by creating and executing an instance of the standard HistogramTransformation process. Omitting required #includes:

Code: [Select]
function ApplySTF( img, stf )
{
   var HT = new HistogramTransformation;
   HT.H = [[stf[0][1], stf[0][0], stf[0][2], stf[0][3], stf[0][4]],
           [stf[1][1], stf[1][0], stf[1][2], stf[1][3], stf[1][4]],
           [stf[2][1], stf[2][0], stf[2][2], stf[2][3], stf[2][4]],
           [ 0, 0.5, 1, 0, 1]];

   var wtmp = new ImageWindow( 1, 1, 1,
      img.bitsPerSample, img.sampleType == SampleType_Real, img.colorSpace != ColorSpace_Gray );

   var v = wtmp.mainView;

   v.beginProcess( UndoFlag_NoSwapFile );
   v.image.assign( img );
   v.endProcess();

   HT.executeOn( v, false ); // no swap file
   img.assign( v.image );

   wtmp.forceClose();
}

and this function can be called in this way:

Code: [Select]
var img = new Image( ...
ApplySTF( img, ImageWindow.activeWindow.currentView.stf );

Let me know if this helps. Of course, if you don't want to use a temporary ImageWindow object, the histogram transformations can be implemented with pure JavaScript code, but that's a bit slow...
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: PJSR: Drawing Image into Graphics with STF
« Reply #2 on: 2009 July 23 11:01:01 »
Juan,

I am going to give it a try. I will let you know if this is what I need.

Thanks a lot,

Georg

Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)