Author Topic: First PI Java Script: Runs, but no undo possible ..  (Read 7182 times)

Offline Christoph Puetz

  • PixInsight Addict
  • ***
  • Posts: 150
  • Peterberg Observatory (Germany, Saarland)
    • Fotos
First PI Java Script: Runs, but no undo possible ..
« on: 2010 August 24 11:09:50 »
Hi all,

I am a software developer (but mainly on databases and other languages).
Nevertheless I like to experiment with PI in order to develop a script, which will give me in future a greater
variety of well-known convolution matrices, that I want to select from a list.

But first - I tried to write this small script (from reading and learning from the examples round here).
It's very basic and it executes without error.
But I cannot do "undo" function in order to restore the image before execution, so I think I made something wrong.
Unfortunately there is not enough documentation so that I can try to find the error myself.

Thanks in advance for any help ....
Christoph
----------------------------------
#include <pjsr/UndoFlag.jsh>

function main()
{
        var window = ImageWindow.activeWindow;
        if ( window.isNull )
             throw new Error( "No active image" );


        var vw = ImageWindow.activeWindow.mainView;
        var img = vw.image;

        console.show();
        console.writeln( "<end><cbr><br><b>" + window.currentView.fullId + "</b>" );
        console.writeln( "Running FreeConvolve code." );
        console.flush();

        console.abortEnabled = false;
        vw.beginProcess( UndoFlag_NoSwapFile );
        console.writeln( "Executing FreeConvolve code." );
        console.flush();
        img.convolve([   0,0,1,0,0,
                             0,0,0,0,0,
                             0,0,2,0,0,
                             0,0,0,2,0,
                             1,0,1,0,0 ]);

        vw.endProcess();

}

main();

Kind regards,
      Christoph
---
ATIK 383L+, Canon EOS 450d, modified,
Canon EOS 500d, 
20" Planewave CDK, 6" APO Starfire Refractor,
Celestron 8", Skywatcher ED80,
Peterberg Observatory (www.sternwarte-peterberg.de)
PixInsight, PHD-Guiding
private URL: www.ccdsky.eu

Offline Enzo De Bernardini

  • PTeam Member
  • PixInsight Addict
  • ***
  • Posts: 274
  • Resistance is futile.
    • Astronomí­a Sur
Re: First PI Java Script: Runs, but no undo possible ..
« Reply #1 on: 2010 August 24 11:20:55 »
Hi Christoph,

I don't have much PSJR experience, but I think that not being able to undo is because these two lines:

#include <pjsr/UndoFlag.jsh>

vw.beginProcess( UndoFlag_NoSwapFile );

You can comment the firstone and modify the second:

vw.beginProcess();

The flag prevent the undo action. That might solve it.

I hope it helps.

Regards,

Enzo.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: First PI Java Script: Runs, but no undo possible ..
« Reply #2 on: 2010 August 24 12:08:40 »
Hi Christoph,

Welcome to PixInsight development!

Enzo has already nailed the problem: remove UndoFlag_NoSwapFile and your script will be undoable.

If you have to convolve images with larger kernels, you may be interested in FFT-based convolution instead of convolution in the spatial domain. For kernel sizes larger than about 15x15 pixels, calling Image.convolveFFT() is more efficient than Image.convolve(), and the difference in performance grows exponentially with increasing kernel sizes.
 
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Christoph Puetz

  • PixInsight Addict
  • ***
  • Posts: 150
  • Peterberg Observatory (Germany, Saarland)
    • Fotos
Re: First PI Java Script: Runs, but no undo possible ..
« Reply #3 on: 2010 August 25 01:00:07 »
Hi,

thanks for your help !!
I will now continue to develop the script.

Feel free to give me some input of commonly used matrices that might be interesting for you !

Christoph
Kind regards,
      Christoph
---
ATIK 383L+, Canon EOS 450d, modified,
Canon EOS 500d, 
20" Planewave CDK, 6" APO Starfire Refractor,
Celestron 8", Skywatcher ED80,
Peterberg Observatory (www.sternwarte-peterberg.de)
PixInsight, PHD-Guiding
private URL: www.ccdsky.eu

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: First PI Java Script: Runs, but no undo possible ..
« Reply #4 on: 2010 August 25 05:08:41 »
If you want to create a list with common convolutions, I may send you a large list ;)
Seriously, we created a list of convolutions in the very first PixInsight STD (previous to the PI Core). It has been saved in a non text format, so I'll have to run that old PI to recover the list. Give me some time :)
Regards,

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

Offline Christoph Puetz

  • PixInsight Addict
  • ***
  • Posts: 150
  • Peterberg Observatory (Germany, Saarland)
    • Fotos
Thanks for your help.
Carlos: Waiting for your input.

In the meantime here is an "alpha" Release of the possible Script.
It lets the user select from a list of the Common Convolution Matrices.

Kind regards,
      Christoph
---
ATIK 383L+, Canon EOS 450d, modified,
Canon EOS 500d, 
20" Planewave CDK, 6" APO Starfire Refractor,
Celestron 8", Skywatcher ED80,
Peterberg Observatory (www.sternwarte-peterberg.de)
PixInsight, PHD-Guiding
private URL: www.ccdsky.eu

Offline Harry page

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1458
    • http://www.harrysastroshed.com
Re: First PI Java Script: Runs, but no undo possible ..
« Reply #6 on: 2010 August 26 11:39:27 »
Hi

Great little script PI sometimes forgets the basics  O:)


Harry
Harry Page

Offline Christoph Puetz

  • PixInsight Addict
  • ***
  • Posts: 150
  • Peterberg Observatory (Germany, Saarland)
    • Fotos
Re: First PI Java Script: Runs, but no undo possible ..
« Reply #7 on: 2010 August 26 12:13:59 »
Thanks Harry,

hope I will receive more input from Carlos - he intended to send me some common matrices
from PI LE.
The small 3x3 matrices can be used to supress some noise or defect pixels, sharping is only recommended
for planets or moon pictures, because noise increases fast.

CS Christoph
Kind regards,
      Christoph
---
ATIK 383L+, Canon EOS 450d, modified,
Canon EOS 500d, 
20" Planewave CDK, 6" APO Starfire Refractor,
Celestron 8", Skywatcher ED80,
Peterberg Observatory (www.sternwarte-peterberg.de)
PixInsight, PHD-Guiding
private URL: www.ccdsky.eu

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: First PI Java Script: Runs, but no undo possible ..
« Reply #8 on: 2010 August 26 12:30:56 »
PI STD (very oooooold release... around 2004/2005). It runs only in windows (and I'm linux based right now). I'll dig on my backups tonight to recover that.
Regards,

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

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: First PI Java Script: Runs, but no undo possible ..
« Reply #9 on: 2010 August 26 18:51:43 »
3x3 Blur

1 2 1

2 4 2

1 2 1



5x5 Blur

1 1 2 1 1

1 2 3 2 1

2 3 4 3 2

1 2 3 2 1

1 1 2 1 1



7x7 Blur

1 1 1 2 1 1 1

1 1 2 2 2 1 1

1 2 3 3 3 2 1

2 2 3 4 3 2 2

1 2 3 3 3 2 1

1 1 2 2 2 1 1

1 1 1 2 1 1 1



3x3 Sharpen

0 -1 0

-1 5 -1

0 -1 0



3x3 Hard Sharpen

0 -2 0

-2 9 -2

0 -2 0



3x3 Mild Sharpen

0 -1 0

-1 6 -1

0 -1 0



5x5 Mexican Hat

0 0 -0.005 0 0

0 -0.406 0 -0.406 0

-0.005 0 1 0 -0.005

0 -0.406 0 -0.406 0

0 0 -0.005 0 0



3x3 Emboss

-1 0 0

0 0 0

0 0 1



3x3 Heavy Emboss

-1 -1 0

-1 0 1

0 1 1



3x3 Laplacian 4

0 -1 0

-1 4 -1

0 -1 0



3x3 Laplacian 8

-1 -1 -1

-1 8 -1

-1 -1 -1



3x3 Edge North (Sobel operator)

-1 -2 -1

0 0 0

1 2 1



3x3 Edge South (Sobel operator)

1 2 1

0 0 0

-1 -2 -1



3x3 Edge East (Sobel operator)

1 0 -1

2 0 -2

1 0 -1



3x3 Edge West (Sobel operator)

-1 0 1

-2 0 2

-1 0 1



3x3 Edge Diagonal

0 1 0

-1 0 1

0 -1 0



3x3 Weighted Laplacian 8

-1 -2 -1

-2 12 -2

-1 -2 -1



5x5 B3-Spline

0.0039 0.0156 0.234  0.0156 0.0039

0.0156  0.0625 0.0938 0.0625  0.0156

0.0234 0.0938  0.1406 0.0938  0.0234

0.0156  0.0625 0.0938 0.0625  0.0156

0.0039 0.0156 0.234  0.0156 0.0039



5x5 Linear

0.0156 0.0312 0.0625 0.0312 0.0156

0.0312 0.0625 0.125 0.0625 0.0312

0.0625 0.125 0.25 0.125 0.0625

0.0312 0.0625 0.125 0.0625 0.0312

0.0156 0.0312 0.0625 0.0312 0.0156



3x3 Linear

0.0625 0.125 0.0625

0.125 0.25 0.125

0.0625 0.125 0.0625



3x3 Small-Scale

0.0625 0.125 0.0625

0.125 10 0.125

0.0625 0.125 0.0625



Backwards X Gradient

0 0 0

-1 1 0

0 0 0



Forwards X Gradient

0 0 0

0 -1 1

0 0 0



Backwards Y Gradient

0 -1 0

0 1 0

0 0 0



Forwards Y Gradient

0 0 0

0 -1 0

0 1 0



Prewitt East

1 0 -1

1 0 -1

1 0 -1

(other Prewitt operators are 7 rotations of the coefficients around the center)



Fei-Chen East

1 0 -1

1.4142 0 -1.4121

1 0 -1

(idem)



Prewitt Compass East

1 1 -1

1 -2 -1

1 1 -1

(idem)



Kirsch East

5 -3 -3

5 0 -3

5 -3 -3



3x3 Average

1 1 1

1 1 1

1 1 1



Other common convolutions families:

Gauss

Mexican Hat

Top Hat

(it is better to calculate the coefficients from formula)
Regards,

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