Author Topic: Convolution extension - negative values  (Read 6567 times)

Offline darkownt

  • PixInsight Enthusiast
  • **
  • Posts: 92
Convolution extension - negative values
« on: 2009 December 05 09:28:08 »
Hi:


I'd like the image.convolution JavaScript command to be extended to be able to utilize negative values in the convolution kernal.

I would also request that the convolution process/interface that is introduced at a later date into the PixInsight core also include the capability to utilize negative values.


cheers
Colin

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Convolution extension - negative values
« Reply #1 on: 2009 December 05 11:12:53 »
Hi Colin,

Image.convolve() can be used with any kernel element values. When a kernel filter has negative values, you must specify a kernel weight explicitly. For example:

Code: [Select]
var sharpen = [ 0, -1,  0,
               -1,  5, -1,
                0, -1,  0 ];

var view = ImageWindow.activeWindow.currentView;
with ( view )
{
   beginProcess();
   image.convolve( sharpen, 1.0 ); // explicit unit kernel weight  
   endProcess();
}

You can specify other weights, not necessarily one, depending on your filter and what you want to achieve.

Open an image and run this little script. It applies a classical sharpen filter.

Feel free to play with different kernel filters. Note that the above sharpen filter preserves flux because the sum of its elements is one.

(edited: fixed wrong filter elements)
« Last Edit: 2009 December 05 11:39:03 by Juan Conejero »
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline darkownt

  • PixInsight Enthusiast
  • **
  • Posts: 92
Re: Convolution extension - negative values
« Reply #2 on: 2009 December 07 14:03:39 »
Thanks Juan!

I've added that into my script.

BTW Is there any image format that supports negative values produced by PixelMath?  A-B seems to truncate values where B>A...

I'm trying to generate convolution filters with + and - numbers from images with + and - numbers in them.

I have a script which can take an image and use it as the convolution kernal.  To get my negative numbers, in the script I shift the image by a value (usually the negative of the median) to get my convolution filter just before I apply it.  It would be much easier to use pixel math to create a zero centered + and - image, before applying my script without the shift.

cheers
Colin

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Re: Convolution extension - negative values
« Reply #3 on: 2009 December 10 14:17:23 »
Hi Colin

If you avoid PixelMath, i.e. manually operate the images/pixels (not sure if this works with JavaScrip... I do that all the time with C++/PCL), any floating point format is capable of negative values support. They will be displayed oddly, but, it works.

Regards,

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