Hi,
This is a small script from
other thread that applies a simple convolution with a low-pass filter. It was originally intended to be part of a star shaping procedure. The idea is to generate a special star mask (a mask that is not black only for stars larger than a given size), e.g. with wavelets, activate it on the target image of interest, and then apply this script. Hey, and it works well 8)
There is no user interface; any changes must be made by editing the source code. I wrote a filter that has a somewhat prominent central value, with the purpose of preserving reasonable stellar profiles. But of course you can experiment with anything representable as a kernel filter; it's pretty straightforward. Nothing stops you from trying a high-pass filter, for example, or anything more exotic.
More technically now. Actually, what makes this script of special interest? As I've said, the intent was to apply a star shaping procedure, so the script must work masked. Fine. But then we have a small problem: script actions cannot be masked...
The solution is to create a temporary working image as a copy of the target image, convolve it with a kernel filter, and then merge it with the target image (through its active mask) with a dynamically generated instance of the PixelMath process. This is possible because all installed processes are automatically scriptable in PixInsight. Since PixelMath is of course a maskable process, we have our cookie and can eat it :mrgreen:
Here we go:
#include <pjsr/ColorSpace.jsh>
#include <pjsr/UndoFlag.jsh>
function main()
{
// Hide the processing console window (only if it isn't a floating window,
// i.e. if it's docked).
console.hide();
// Get access to the currently active image window.
var window = ImageWindow.activeWindow;
// Do we have one?
if ( window.isNull )
throw Error( "There is no active image window!" );
// Get access to its main view, so we can pick some properties of the image
// it encapsulates.
var view = window.mainView;
// Create a working image with identical parameters to the target image.
var workingWindow = new ImageWindow( view.image.width,
view.image.height,
view.image.numberOfChannels,
window.bitsPerSample,
window.isFloatSample,
view.image.colorSpace != ColorSpace_Gray,
"temporary" );
// Access to the working image's main view
var workingView = workingWindow.mainView;
// Begin processing the working view's image. Since this is a temporary
// working object, we don't want to write a swap file to undo it.
workingView.beginProcess( UndoFlag_NoSwapFile );
// Copy the target image to our working image
workingView.image.apply( view.image );
// Apply a convolution. This is the magic part :o)
workingView.image.convolve( [ 1, 2, 4, 2, 1,
2, 6, 12, 6, 2,
4, 12, 24, 12, 4,
2, 6, 12, 6, 2,
1, 2, 4, 2, 1 ] );
// Done with working view. Never forget this, or the PJSR will bite you.
workingView.endProcess();
// Now create a PixelMath instance to merge our (convolved) working image
// with the target image. Hopefully, this will happen through a mask.
var mergeThem = new PixelMath;
mergeThem.expression = workingView.id;
mergeThem.useSingleExpression = true;
mergeThem.rescale = false;
mergeThem.executeOn( view );
// Job done: destroy our working image.
workingWindow.close();
}
main();