First PI Java Script: Runs, but no undo possible ..

cpuetz

Well-known member
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>
<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();

 
Hi Christoph,

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

Code:
#include <pjsr/UndoFlag.jsh>

Code:
vw.beginProcess( UndoFlag_NoSwapFile );

You can comment the firstone and modify the second:

Code:
vw.beginProcess();

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

I hope it helps.

Regards,

Enzo.
 
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.
 
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
 
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 :)
 
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.

 

Attachments

  • lotsofconvolution.js
    6.8 KB · Views: 50
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
 
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.
 
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)
 
Back
Top