Author Topic: Problems with Image.ATW  (Read 8339 times)

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
Problems with Image.ATW
« on: 2007 October 24 14:37:50 »
while (1) puts ("problems ");

Let's see ;)

Code: [Select]
#include <pjsr/UndoFlag.jsh>

var win = ImageWindow.activeWindow;  // no err checking
var v = win.mainView;

var k = [
    1/256, 1/64, 3/128, 1/64, 1/256,
    1/64,  1/16, 3/32,  1/16, 1/64,
    3/128, 3/32, 9/64,  3/32, 3/128,
    1/64,  1/16, 3/32,  1/16, 1/64,
    1/256, 1/64, 3/128, 1/64, 1/256
];
var ss = 80;  // scalingSequence
var nl = 1;  // numberOfLayers

var atw = v.image.ATW (k, nl, ss);
var w = new ImageWindow (1, 1, 1, 32, true, false, "wvlt_without_"+ss);
with (w.mainView) {
    beginProcess (UndoFlag_NoSwapFile);
    image.transfer (atw[nl]);  // get residual
    //image.rescale(); // the residual layer isn't to be rescale()d
    endProcess();
}
w.show();
w.zoomToFit();


I have two problems with this code:

1) increasing the scalingSequence results in almost identical images. Performing the difference between the residual layer when 'ss = 16' and the one when 'ss = 100' resulted in an image that resembled like the layer of 4 pixels more or less. I don't understand this, I expect to get a somewhat blurred image when 'ss = 16' and a definitely blurred one when 'ss = 100'.

2) setting numberOfLayers to a number greater than 1, gives really weird results. Try 'nl = 2' and 'ss = 16'. I restarted PixInsight in an attempt to see if this was a memory corruption problem that would go away but (fortunately?) it isn't and I was able to reproduce it.

$ perl -le 'print q[problems ] while 1'
--
 David Serrano

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Problems with Image.ATW
« Reply #1 on: 2007 October 24 19:38:52 »
As long as I understand your code (and what is supposed to be happening internally), I think that this behavior is completelly normal. Changing the scaling sequence yields absolutly no differences on the first layer. The sequence sets the spacing, or holes, in the subsecuent layers, wich are incorporated between the kernel values. So, if you want to use just one layer, but increase/decrease the blurring effect, you'll just have to change the kernel.


About your second problem... well, it seems that the code is right (anyway, I'll check it tomorrow). Could you explain what you get?
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/
Problems with Image.ATW
« Reply #2 on: 2007 October 25 01:31:06 »
Hi David,

As Carlos says, all is perfectly normal. If you perform a wavelet decomposition with just one detail layer, the first layer and the residual layer should be identical, no matter the scaling sequence (ss in your code), as long as you don't change the scaling function (k in your code).

This is logical. Consider that the first wavelet layer contains only structures with characteristic sizes less or equal to one pixel. These structures are invariant to the scaling sequence.

The true fun starts with two or more layers. Then the scaling sequence determines the distance in pixels between two successive wavelet scales.

Now, I must caution you against using linear scaling sequences (that is, when ss > 0), especially with large values (say more than 6 to 10 pixels). This is allowed in our implementation, and indeed works correctly in the sense that you can perform an inverse transform (wavelet reconstruction) to get the original, untransformed image. However, if you modify or suppress a wavelet layer obtained with linear scaling, you can get some artifacts in the reconstructed image. You can check this very easily with the standard ATrousWaveletTransform process. The artifacts manifest as increased brightness following horizontal and vertical regular patterns.

The reason for this behavior is that the à trous discrete wavelet transform algorithm utilizes a dyadic scaling sequence (1,2,4, ..., 2^n) to decompose the image into wavelet layers. If we use a different sequence, we are not performing a true à trous transform. As long as we don't modify any wavelet layer, the algorithm is perfectly reversible using any scaling sequence, because it is a purely linear transform with respect to scale (say size in this context). However, if we modify a single wavelet coefficient with a non-dyadic sequence, the reconstruction algorithm is no longer working as such, but as an approximation. These approximations work pretty well as long as we don't depart too much from the true dyadic sequence.

The linear scaling feature in our implementation (which AFAIK is unique) is useful to process high-resolution planetary images because it allows us to perform decompositions into scales of, for example, 1,2,3,4... or 1,3,5,7,9,... pixels, which allow for a better separation of small structures. With these sequences, or even somewhat larger ones, there is no problem, or just negligible errors, because they are reasonably similar to a dyadic sequence, so the approximations are quite good. However, with larger sequences (80 pixels is way too large) you're likely to get artifacts if you change some wavelet scales.

Now your second question. The wavelet detail layers (that is all layers except the last residual one) are not true images. They contain wavelet difference coefficients that can take positive, zero and negative values. To show a detail layer as an image, you must first rescale all coefficients to stay within the normalized [0,1] range. The easiest (although not necessarily optimal) way to achieve this is by automatically rescaling it with the Image.rescale() method. In general, when you visualize a wavelet layer in this way you see a weird image with very low contrast. Another way to display wavelet layers is to assign false colors to several ranges of coefficients. For example, you can display positive, zero and negative coefficients using proportional brightness levels of different colors.

<jokes>
Code: [Select]
#include <pcl/Thread.h>

class MyProblemGenerator : public Thread
{
   virtual void Run()
   {
      while ( true ) puts( "problems" );
   }
};

MyProblemGenerator* noProblem = new MyProblemGenerator;

noProblem->Start();

Sleep( 1.0 );
noProblem->Kill(); // I can kill your problems :)
delete noProblem, noProblem = 0;


<disclaimer>
Do not use Thread::Kill() for serious purposes. Don't kill your threads. They don't deserve that.
</disclaimer>
</jokes>
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
Problems with Image.ATW
« Reply #3 on: 2007 October 25 03:45:57 »
Quote from: "Juan Conejero"
the first wavelet layer contains only structures with characteristic sizes less or equal to one pixel.


Hmm, that "less or equal" actually answers one question that I didn't know how to answer. Proactive explanations! :^).


Quote from: "Juan Conejero"
The artifacts manifest as increased brightness following horizontal and vertical regular patterns.


You nailed it! I guess that answers other question I had ("Why can't you select more than 16 pixels in the ATW dialog with linear sequencing?"). I don't know if it's normal to see artifacts even at 4 pixels using almost all scaling functions.


All in all, hats off to your detailed and informative answer :). I guess that the official documentation could include links to some of these conversations, which would have the added effect of making the forum more widespread and opening people the possibility of asking about that exact problem of theirs that isn't clear enough after reading the doc.
--
 David Serrano

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
Problems with Image.ATW
« Reply #4 on: 2007 October 25 08:33:58 »
Also you'll have to take into consideration the scaling function (or kernel). They differ in the degree of allowance to "hide" artifacts. For example, a 5x5 gaussian function is more robust than a 3x3 gaussian one.
Regards,

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