Author Topic: New Script: 33 Common Convolution Matrices  (Read 8848 times)

Offline Christoph Puetz

  • PixInsight Addict
  • ***
  • Posts: 150
  • Peterberg Observatory (Germany, Saarland)
    • Fotos
New Script: 33 Common Convolution Matrices
« on: 2010 September 01 10:26:09 »
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
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: New Script: 33 Common Convolution Matrices
« Reply #1 on: 2010 September 01 10:43:18 »
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 ;)
Regards,

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

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: New Script: 33 Common Convolution Matrices
« Reply #2 on: 2010 September 01 11:18:24 »
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:


 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: [Select]
console.flush();

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

vw.endProcess();

Hope this helps.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: New Script: 33 Common Convolution Matrices
« Reply #3 on: 2010 September 01 11:34:15 »
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).
Regards,

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

Offline Enzo De Bernardini

  • PTeam Member
  • PixInsight Addict
  • ***
  • Posts: 274
  • Resistance is futile.
    • Astronomí­a Sur
Re: New Script: 33 Common Convolution Matrices
« Reply #4 on: 2010 September 01 16:36:11 »
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: [Select]
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.

Offline Christoph Puetz

  • PixInsight Addict
  • ***
  • Posts: 150
  • Peterberg Observatory (Germany, Saarland)
    • Fotos
Re: New Script: 33 Common Convolution Matrices, Version 1.2
« Reply #5 on: 2010 September 02 09:51:53 »
Hi, uploaded Version 1.2 - added img.truncate() as supposed by Juan.
Further extensions coming soon.
Thanks to all !

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 Niall Saunders

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1456
  • We have cookies? Where ?
Re: New Script: 33 Common Convolution Matrices
« Reply #6 on: 2010 September 02 11:43:07 »
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.
Cheers,
Niall Saunders
Clinterty Observatories
Aberdeen, UK

Altair Astro GSO 10" f/8 Ritchey Chrétien CF OTA on EQ8 mount with homebrew 3D Balance and Pier
Moonfish ED80 APO & Celestron Omni XLT 120
QHY10 CCD & QHY5L-II Colour
9mm TS-OAG and Meade DSI-IIC