New Script: 33 Common Convolution Matrices

cpuetz

Well-known member
Dear PI Users,

this is my first PJSR script. It features a collection of 33 common convolution matrices, that can be selected by Menu-Entry and
applied to your picture(s).

It can easily be extended and I plan to do so in future, so check for updates regularly, please.
After installation the Script can be called by Menu->Scripts->Common Convolution Matrices.

Hope it may be useful for you.

Kind regards,
Christoph
 

Attachments

Good job. One possible future addition could be to draw the convolution kernel, or to display the coefficients. :) Keep the good work comming


PS: Thanks for the citation ;)
 
Hi Christoph,

Welcome to PixInsight development, and congratulations on a nice script!

The script works nicely for low-pass filters, but convolution with a high-pass filter requires fixing out-of-range values.

For example, if you convolve with a sharpening filter such as:

Code:
 0  -1   0
-1  +6  -1 
 0  -1   0

there can be values outside the [0,1] range in the convolved result. This happens because the convolution routine applies a unit filter weight when there are one or more negative filter coefficients.

There are two ways of fixing out-of-range values: truncation and rescaling. Truncation to [0,1] is the standard procedure; it causes some data loss due to ringing, but preserves the overall brightness of the convolved image. Rescaling keeps all the data at the cost of a loss of dynamics, which is a nonstandard procedure (useful in some contexts, but not in the context of general image filtering).

So I think you should add a call to Image.truncate() in line #399 of your script, just after calling Image.convolve():

Code:
	console.flush();

        img.convolve( conv_matrix );
        img.truncate();

	vw.endProcess();

Hope this helps.
 
Long live out of range values!!!! Don't opress them!!!!

:D

Jokes apart, for a high pass filter like that one, this truncation or rescalation makes a lot of sence, while for other operators, like the edge detectors (gradients), or laplacians, out of range values have a very meaningful meaning, that should not be changed.

This reminds me that we have to deeply discuss this topic, on future development (and btw, I can't see why complex images cannot be managed by the UI).
 
Nice script Christoph, thanks for your work!  :D

A small suggestion that might be useful for the future: when there is only one value to compare, instead of using many IF, you can use a single SWITCH. For example:

Code:
switch( index ) {
  case 1:
    conv_matrix = [ 1, 1, 1,
                    1, 1, 1,
                    1, 1, 1 ];
  break;
  case 2:
    conv_matrix = [ 1, 1, 1,
                    1, 2, 1,
                    1, 1, 1 ];
  break;
};

The result is the same, of course.

Best regards,

Enzo.
 
Hi, uploaded Version 1.2 - added img.truncate() as supposed by Juan.
Further extensions coming soon.
Thanks to all !

Christoph
 

Attachments

Keep up the good work Christoph,

And don't be too concerned if you don't see too many 'downloads' - a lot of folk will pick and choose what they need from these kind of code developments. For example, I have not YET downloaded your script, but I AM keeping a close eye on how it develops. Personally, I will 'jump in' as and when I can devote some time to actually 'playing' with your script - but the whole concept is definitely one of interest to me.
 
Back
Top