Quantcast Avisynth: Wavelet Denoising? - digitalFAQ.com Forums [Archives]
  #1  
11-08-2002, 01:20 PM
GFR GFR is offline
Free Member
 
Join Date: May 2002
Posts: 438
Thanks: 0
Thanked 0 Times in 0 Posts
After someone (blackprince?) posted a link about it I studied some references about wavelet noise reduction and it seems really promising.

The idea is the following (very simplified):

At each level of a Wavelet transform, you split the image in two components: a "blured" component (low-pass) and a "detail" component (high-pass).

If you look at the "detail" component, most of it should be zero, except where you have, well, details: edges, textures. When you have noise, instead of mostly zero, you have random small amplitude points (the noise) with the higher amplitude edges and textures.

If you "gate" this "detail" component so that these small points due to noise are zeroed and the higher amplitude edges and textures are kept untouched, and then combine it with the "blured" component, the noise is killed but the edges and textures are as sharp as before!

This is unlike traditional smoothing where all high frequencies are attenuated, and by the time noise is killed the edges and textures are also smoothed...

Besides removing normal "white" noise, it is also impressive at removing block noise if your source is a low bitrate AVI or MPEG file

One nice feature is that you can try to estimate an "optimal" threshold automatically from the variance of the "detail" component.

I have programmed an implementation of it in Delphi (that works with still images), I'll try to translate it to C and compile as a AVISynth filter. (the original filter documentation is in Japanese and it won't work with my old Pentium II , it needs SSE).
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Site Staff / Ad Manager
 
Join Date: Dec 2002
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
  #2  
11-08-2002, 04:14 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Hi GFR,

Is there a reference model or a definition in C, C++ ?
I'm interested in looking at that

-kwag
Reply With Quote
  #3  
11-11-2002, 06:45 AM
GFR GFR is offline
Free Member
 
Join Date: May 2002
Posts: 438
Thanks: 0
Thanked 0 Times in 0 Posts
You can find some C/C++ or Matlab libraries on the web (try it in Google).

While there are many different wavelets you can try (each one with its pros and cons) the wavelet I'm trying to code is a very simple algorythm called "lifting".

It's like this:

1) Split the image in two sub-images, one with the even colums, the other with the odd columns (the first column is column 0).

2) Make the odd image = odd - even. The odd image is now a high pass in the horizontal direction (note: it can be negative).

3) Make the even image = even + odd div 2 This makes the even image a low pass in the horizontal direction.

4) Split each of the two subimages into even and odd lines, and now calculate odd-odd as a high pass in horizontal and vertical directions ("corners" detail), odd-even is high pass in H and low pass in V (vertical edges), even-odd is low pass H high pass V (horizontal edges) and the even-even is a lower resolution version of the original image.

5) If you want you can run the even-even image through the algorythm again for another level of the transform and so on.

You can estimate the variance of the noise using the highest resolution odd-odd image, because it is problably mostly noise. The median of the aboslute deviation to the median is said to be a good estimative.

Now "gate" all the detail images with
x=0 if abs(x)<thresh
x=x-sign(x)*thresh if abs(x)>=thresh

Or any other gating function you want (this one avoids creation of false oscillations).

Use the thresh=k*(variance of the noise), k from 2 to 3 should be good enough (the optimal k is subject of many researches). You can also try a different thresh for each subimage.

The inverse transform is straightforward, just make even=even-odd div 2, odd = odd+even and interleave the even with odd.

Good things:
1) very fast, few operations, can be all integer.
2) no need for extra memory, the calculations can be in-place (you don't actually split the images just keep track of the pointers)

Bad things:
it's not the smoothest wavelet around and it is not the one that best decorrelates the low freq coeffs from the high freq ones.

I hope the Delphi code is working today, I can post it to you if you want it.
Reply With Quote
  #4  
11-11-2002, 07:41 AM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Hi GFR,

Sure!, post it. I would be nice if it can be ported to C. My Pascal (Dephi) programming is very (VERY) rusty, but I should be able to read the code and do an un-optimized working port to C, and then worry about optimizations. It would be very interesting if this would complement SansGrip "Blockbuster" filter

-kwag
Reply With Quote
  #5  
11-11-2002, 10:42 AM
GFR GFR is offline
Free Member
 
Join Date: May 2002
Posts: 438
Thanks: 0
Thanked 0 Times in 0 Posts
Just the forward transform - I'm debugging the backward transform.
It seems long but it's repetitive and can problably be optimized.
Nothing special, only you have to be careful so that you know which index is pointing to what!

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  BitMap1,BitMap2:TBitMap;
  i,j: Integer;
  tempint,tempint2:Integer;
  Line1,Line2:PByteArray; // Delphi pointer to an array of Bytes
  sigma,lambda,t: real;
begin
  BitMap1:=Image1.Picture.Bitmap;
  BitMap2:=Image4.Picture.Bitmap;

  // I copy Image1 to (invisible) Image4
  // so I have the original Image to compare to 
  // You can do it all in place
  
  For i:=0 to BitMap1.Height-1 do
    begin
      Line1:=BitMap1.ScanLine[i]; // Line1 points to line i of Image1
      Line2:=BitMap2.ScanLine[i]; // Line2 points to line i of Image4
      For j:=0 to BitMap1.Width-1 do
        Line2[j]:=Line1[j]; // Get each pixel i,j
    end;

  {Take even,odd COLUMNS
   odds:=err (odd-even)
   even:=mean (even+1/2*err)
  }
  for j:=0 to BitMap2.Height-1 do // Scan the j lines
    begin
      Line2:=BitMap2.ScanLine[j];
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          tempint2:=Max(Min(Line2[2*i+1]-Line2[2*i],127),-127);
          // column 2*i+1 are the odd columns
          // I clip the values to the range -127..127
          tempint:=Line2[2*i] + (tempint2 div 2);
          // column 2*i are even columns
          // I used tempint and tempint2 because the Bitmaps only handle unsigned
          // bytes in the range 0..255
          {high-pass - odds}
          Line2[2*i+1]:=128+tempint2;
          // Add a DC level 128 so that it's in the appropriate range
          // And you can store it in the bitmap and preview it
          {passa-baixas - pares}
          Line2[2*i]:=tempint;
        end;
    end;

  {draws the bitmap}
  // I use Image2 to draw because Image4 is "scrambled"
  // This draws a low pass, squashed picture on the left and the high pass on the right
  {        L | H        }
  Bitmap1:=Image2.Picture.Bitmap;
  for j:=0 to BitMap2.Height-1 do
    begin
      Line2:=Bitmap2.ScanLine[j];
      Line1:=Bitmap1.ScanLine[j];
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          Line1[i]:=Line2[2*i];
          Line1[i+(Image1.Width div 2)]:=Line2[2*i+1];
        end;
    end;

  Image2.Invalidate; // forces the Image to redraw


  {Take even,odd LINES
   odds:=err (odd-even)
   even:=mean (even+1/2*err)
  }
  for j:=0 to (BitMap2.Height div 2)-1 do // scan the lines
    begin
      Line1:=BitMap2.ScanLine[2*j]; // even lines
      Line2:=BitMap2.ScanLine[2*j+1]; // odd lines
      for i:=0 to BitMap2.Width-1 do
        begin
          tempint2:=Max(Min(Line2[i]-Line1[i],127),-127);
          tempint:=Line1[i] + (tempint2 div 2);
          {passa-altas - impares}
          Line2[i]:=128+tempint2;
          {passa-baixas - pares}
          Line1[i]:=tempint;
        end;
    end;

  {draws}
  {don't care about sigma it's an estimate of the variance but it's not correct}
  {the picture is arranged like this
  
    LL | HL
    ---+---
    LH | HH
    
  }
  {You don't need to draw this but it is very useful for debugging
   and for learning about the images and wavelets}
  sigma:=0;
  Bitmap1:=Image2.Picture.Bitmap;
  for j:=0 to (BitMap2.Height div 2)-1 do
    begin
      Line2:=Bitmap2.ScanLine[2*j];
      Line1:=Bitmap1.ScanLine[j];
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          Line1[i]:=Line2[2*i];
          Line1[i+(Image1.Width div 2)]:=Line2[2*i+1];
        end;
      Line2:=Bitmap2.ScanLine[2*j+1];
      Line1:=Bitmap1.ScanLine[j+(BitMap2.Height div 2)];
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          Line1[i]:=Line2[2*i];
          Line1[i+(Image1.Width div 2)]:=Line2[2*i+1];
          sigma:=sigma+{sqr(Line2[2*i+1]-128)}abs(Line2[2*i+1]-128); {MAD?}
        end;
    end;

  sigma:=(sigma/((BitMap2.Width/2)*(BitMap2.Height/2)))/0.6745{sqrt(sigma/((BitMap2.Width/2)*(BitMap2.Height/2)))};
  lambda:=sqrt(2*Log10((BitMap2.Width)*(BitMap2.Height)));
  t:=sigma*lambda;
  // write to the screen to debug the variance estimate
  Label2.Caption:=FloatToStr(sigma);
  Edit1.Text:=FloatToStr(lambda);
  Label5.Caption:=FloatToStr(t); 

  Image2.Invalidate;

  {The nest level or SCALE}

  {Takes COLUMNS *4 ("evens"), *4+2 ("odds")
   odds:=err(odds-evens)
   evens:=mean (ebens+1/2*err)
  }
  for j:=0 to (BitMap2.Height div 2)-1 do // scan 1 column out of 4
    begin
      Line2:=BitMap2.ScanLine[2*j];
      for i:=0 to (BitMap2.Width div 4)-1 do
        begin
          tempint2:=Max(Min(Line2[4*i+2]-Line2[4*i],127),-127);
          tempint:=Line2[4*i] + (tempint2 div 2);
          {passa-altas - impares}
          Line2[4*i+2]:=128+tempint2;
          {passa-baixas - pares}
          Line2[4*i]:=tempint;
        end;
    end;

  {draws}
  {    LLL | LLH |   HL      
           |     |
    -------+-----+-----------
                 |
          LH     |   HH
                 |                 }                 
  Bitmap1:=Image2.Picture.Bitmap;
  for j:=0 to (BitMap2.Height div 2)-1 do
    begin
      Line2:=Bitmap2.ScanLine[2*j];
      Line1:=Bitmap1.ScanLine[j];
      for i:=0 to (BitMap2.Width div 4)-1 do
        begin
          Line1[i]:=Line2[4*i];
          Line1[i+(Image1.Width div 4)]:=Line2[4*i+2];
        end;
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          Line1[i+(Image1.Width div 2)]:=Line2[2*i+1];
        end;
      Line2:=Bitmap2.ScanLine[2*j+1];
      Line1:=Bitmap1.ScanLine[j+(BitMap2.Height div 2)];
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          Line1[i]:=Line2[2*i];
          Line1[i+(Image1.Width div 2)]:=Line2[2*i+1];
        end;
    end;

   Image2.Invalidate;

  {Takes LINES *4 ("evens"), *4+2 ("odds")
   odds:=err(odds-evens)
   evens:=mean (ebens+1/2*err)
  }
  for j:=0 to (BitMap2.Height div 4)-1 do // each line out of 4
    begin
      Line1:=BitMap2.ScanLine[4*j];
      Line2:=BitMap2.ScanLine[4*j+2];
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          tempint2:=Max(Min(Line2[2*i]-Line1[2*i],127),-127);
          tempint:=Line1[2*i] + (tempint2 div 2);
          {passa-altas - impares}
          Line2[2*i]:=128+tempint2;
          {passa-baixas - pares}
          Line1[2*i]:=tempint;
        end;
    end;

  {draws}
  {    LLLL | LLHL |   HL      
    --------+------+        
       LLLH | LLHH |
    --------+------+-----------
                   |
          LH       |   HH
                   |                 }                 
  Bitmap1:=Image2.Picture.Bitmap;
  for j:=0 to (BitMap2.Height div 4)-1 do
    begin
      Line2:=Bitmap2.ScanLine[4*j];
      Line1:=Bitmap1.ScanLine[j];
      for i:=0 to (BitMap2.Width div 4)-1 do
        begin
          Line1[i]:=Line2[4*i];
          Line1[i+(Image1.Width div 4)]:=Line2[4*i+2];
        end;
      Line2:=Bitmap2.ScanLine[4*j+2];
      Line1:=Bitmap1.ScanLine[j+(BitMap2.Height div 4)];
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          Line1[i]:=Line2[4*i];
          Line1[i+(Image1.Width div 4)]:=Line2[4*i+2];
        end;
    end;
  for j:=0 to (BitMap2.Height div 2)-1 do
    begin
      Line2:=Bitmap2.ScanLine[2*j];
      Line1:=Bitmap1.ScanLine[j];
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          Line1[i+(Image1.Width div 2)]:=Line2[2*i+1];
        end;
      Line2:=Bitmap2.ScanLine[2*j+1];
      Line1:=Bitmap1.ScanLine[j+(BitMap2.Height div 2)];
      for i:=0 to (BitMap2.Width div 2)-1 do
        begin
          Line1[i]:=Line2[2*i];
          Line1[i+(Image1.Width div 2)]:=Line2[2*i+1];
        end;
    end;

  Image2.Invalidate;

  // enables the threshold setting 
  TrackBar1.Enabled:=true;
  // enable the gating and inverse transform buttons
  Button2.Enabled:=true;
  Button4.Enabled:=false;
end;
Reply With Quote
  #6  
11-12-2002, 09:44 AM
GFR GFR is offline
Free Member
 
Join Date: May 2002
Posts: 438
Thanks: 0
Thanked 0 Times in 0 Posts
Here are some tests I ran:

http://www.geocities.com/gfr.geo/wavelets.html
Reply With Quote
  #7  
11-12-2002, 01:19 PM
GFR GFR is offline
Free Member
 
Join Date: May 2002
Posts: 438
Thanks: 0
Thanked 0 Times in 0 Posts
Hi kwag

Below:

http://www.cs.kuleuven.ac.be/śwavelets/

you can find a C++ wavelet library and some nice articles.

I'm afraid you need some background in signal/image processing to understand these.
Reply With Quote
  #8  
11-12-2002, 01:49 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by GFR
Hi kwag

Below:

http://www.cs.kuleuven.ac.be/śwavelets/

you can find a C++ wavelet library and some nice articles.

I'm afraid you need some background in signal/image processing to understand these.
Hi GFR,

You're right I can read and write code, but I've never gone into signal processing ( DSP's, etc. ) algorithm's that deep
To many things I want to do, not enough time
The most I've done in digital coding is generating a Golay (23,12) encoder in software, using a 6522 PIA (Peripheral Interface Adapter ), for test encoding on paging equipment ( circa 1985 ) . Some info related to what I had to deal with here: http://www.math.uic.edu/~fields/Deco...roduction.html
And that was ~15 years ago . After that, my programming has been in the communications field ( more of I/O control, some embedded stuff ,etc ) but not on video. So I have a lot to learn, before I can start applying my programming concepts in this field

-kwag
Reply With Quote
  #9  
11-13-2002, 02:12 PM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by GFR
After someone (blackprince?) posted a link about it I studied some references about wavelet noise reduction and it seems really promising.
This does sound very interesting, and I'm intrigued about the possibility of including it (or a variation) in NoMoSmooth. Could you post the references?
Reply With Quote
  #10  
11-13-2002, 04:41 PM
black prince black prince is offline
Free Member
 
Join Date: Jul 2002
Posts: 1,224
Thanks: 0
Thanked 0 Times in 0 Posts
Hi SansGrip,

SansGrip wrote:
Quote:
SansGrip Posted: Wed Nov 13, 2002 3:12 pm Post subject: Re: wavelet denoising

--------------------------------------------------------------------------------

GFR wrote:
After someone (blackprince?) posted a link about it I studied some references about wavelet noise reduction and it seems really promising.


This does sound very interesting, and I'm intrigued about the possibility of including it (or a variation) in NoMoSmooth. Could you post the references?
Follow this link for the refrences to wavelet denoising filter. I hope this
helps:


http://www.kvcd.net/forum/viewtopic.php?t=1440

-black prince
Reply With Quote
  #11  
11-14-2002, 05:19 AM
GFR GFR is offline
Free Member
 
Join Date: May 2002
Posts: 438
Thanks: 0
Thanked 0 Times in 0 Posts
References:

http://www.cs.kuleuven.ac.be/śwavelets/

Some publications, a C++ package.

You can find the articles below with google:

IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 9, NO. 9, SEPTEMBER 2000
Adaptive Wavelet Thresholding for Image Denoising
and Compression
S. Grace Chang, Student Member, IEEE, Bin Yu, Senior Member, IEEE, and Martin Vetterli, Fellow, IEEE

On Denoising and Best Signal Representation
Hamid Krim, Senior Member, IEEE, Dewey Tucker, St┤ephane Mallat, Member, IEEE, and David Donoho

DE-NOISING BY
SOFT-THRESHOLDING
David L. Donoho
Department of Statistics
Stanford University

Multimedia Applications
of the Wavelet Transform
(PHD thesis)
Claudia Kerstin Schremmer

Maarten Jansen
pieflab - matlab package, some articles
Reply With Quote
  #12  
11-14-2002, 06:53 AM
GFR GFR is offline
Free Member
 
Join Date: May 2002
Posts: 438
Thanks: 0
Thanked 0 Times in 0 Posts
Copy this and paste in the browser's address bar (without http:// )

www.geocities.com/gfr.geo/smooth-lift.gif

This looks horrible but it is very clear to illustrate the concept.

I'm using the integer lifting wavelet (lazy wavelet) , then CLIPPING the high level details instead of killing the low-level details. Since this particular wavelet produces blocks when you eliminate details, it's very easy to see which portions of the the picture are "smoothed" (in fact "blocked") and which are kept intact.

With a better choice of wavelet this can be a good selective edge blur filter.
Reply With Quote
  #13  
11-15-2002, 11:43 AM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
I threw together a quick filter using the algorithm posted above. I hope I got it right (it seems to reconstruct the image fine, but I'd be grateful if someone could check the source against the description of the algorithm). Currently it only does one pass, and only operates on luma.

You can specify a threshold for each of the detail components. See the readme for usage.

Doesn't seem very effective to me, with low thresholds not really touching the noise and higher ones making the image blocky.

Is this because it only does one pass? How many passes would be good to be effective against noise? Or is it just not a very good type of wavelet? If so, what would be more suitable for denoising?

Incidentally, what would happen if one were to apply this to even/odd frames instead of pixels?
Reply With Quote
  #14  
11-15-2002, 01:28 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by SansGrip
I threw together a quick filter using the algorithm posted above. I hope I got it right (it seems to reconstruct the image fine, but I'd be grateful if someone could check the source against the description of the algorithm). Currently it only does one pass, and only operates on luma.

You can specify a threshold for each of the detail components. See the readme for usage.

Doesn't seem very effective to me, with low thresholds not really touching the noise and higher ones making the image blocky.

Is this because it only does one pass? How many passes would be good to be effective against noise? Or is it just not a very good type of wavelet? If so, what would be more suitable for denoising?

Incidentally, what would happen if one were to apply this to even/odd frames instead of pixels?
Hi SansGrip,

I tested the wavelet filter. But as you said, the lower the values, the lower the filtering. But I still can see the artifacts. If I increase the values, they just get blured, but they are still present. I believe because it is applied on the input stage of the encoder, it won't be as usefull as if it was applied on a output stage of an encoder. Which in this case ( TMPEG, CCE, etc. ) , it's impossible to do. If the encoders had a "Pre filter" hook stage and a "Post filter" hook stage to plug filters, then I believe it would work on the output stage, just as it does on the still images samples presented earlier on this thread. Just my thought

-kwag
Reply With Quote
  #15  
11-15-2002, 04:28 PM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
@kwag, GFR, all:

Quote:
Originally Posted by kwag
I tested the wavelet filter. But as you said, the lower the values, the lower the filtering. But I still can see the artifacts. If I increase the values, they just get blured, but they are still present.
Edit: The most likely reason that the output from this filter is so poor is because of the "lifting" approach, which basically involves halving the resolution and then reconstructing the entire image from that. "Proper" wavelets should perform much better, but of course are slower and less easy to code.

Theoretically speaking wavelets should be a very good technique for denoising. There are several key features of noise that I've identified:

1) Low amplitude
2) High frequency
3) Random

The key features of the details we want to keep are:

1) Low amplitude
2) Mostly low frequency
3) Non-random

Because dumb spatial/temporal softeners usually only pay attention to the first feature of noise (the characteristic low amplitude), they usually annihilate details too (because they're also low amplitude).

In order for a filter to remove noise and nothing else, it needs to answer the following questions:

Low amplitude? No -> Skip
Low frequency? Yes -> Skip
Random? No -> Skip
Replace with (possibly weighted) average

Only if all tests pass should the pixel be considered influenced by noise.

Step 1 is easy, because low amplitude just means "how much does the actual value vary from the average?" If a lot, it's high amplitude. If very little, it's low.

Step 2 is tricky in that it involves some kind of transformation of the signal. Generally to perform frequency analysis on a signal one must transform it into the frequency domain, i.e. using Fourier techniques. These are a pain to code and slow to run.

The nice thing about wavelets is that they let you (with varying effectiveness based on the particular wavelet used) isolate the high-frequency and low-frequency parts of the signal without jumping through too many hoops. They're both (usually) easier to code and faster than Fourier methods.

Step 3 is either very easy or very hard, I've not really thought about it enough yet . Randomness is the defining factor of noise, though, and it's becoming my opinion that any truly non-destructive denoiser must measure the (temporal) randomness of what it thinks is noise. Simply being within a variance threshold is not sufficient.

Another complicating factor is motion. To properly account for motion it's necessary to use motion compensation (aka motion estimation), which is a very tricky thing to code. Motion adaption -- as used in NoMoSmooth -- is a step in the right direction, though it might be rendered redundant if the three steps outlined above are effective.

Anyway, that's a summary of my thoughts over the last few days trying to improve NoMoSmooth. Differentiating between noise and detail is very hard, but wavelets might open an avenue to solving the puzzle.

I'd be very interested to hear about various wavelets and their strengths/weaknesses, preferably without too many mathematical details, at least initially .
Reply With Quote
  #16  
11-15-2002, 04:37 PM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by GFR
If you "gate" this "detail" component so that these small points due to noise are zeroed and the higher amplitude edges and textures are kept untouched, and then combine it with the "blured" component, the noise is killed but the edges and textures are as sharp as before!
Note that the gating must be done only on low-amplitude high-frequency parts of signal. If we could find a wavelet that produces only this component we'd have a much easier time denoising, since we wouldn't have to worry about those low-amplitude low-frequency details that we want to keep.
Reply With Quote
  #17  
11-15-2002, 10:53 PM
snowmoon snowmoon is offline
Free Member
 
Join Date: Nov 2002
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to snowmoon Send a message via AIM to snowmoon
Couldn't a FFT filter be used to get rid of those?
Reply With Quote
  #18  
11-16-2002, 11:35 AM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by snowmoon
Couldn't a FFT filter be used to get rid of those?
FFT is a very effective way of targeting specific frequencies, but it's also a little tricky to code and slower than wavelets (since you have to transform from the spatial domain to the frequency domain, do your processing, then transform back again). That said I'm looking into FFT as a possibility.
Reply With Quote
  #19  
11-16-2002, 12:14 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Hi SansGrip,

This is not related to wavelets, but it might be worth a look.
I found this in the file readpic.c, after studying some sources originally by the MPEG Group, and modified by John Schlichther as used in his program "AVI2MPG1".

Here's the code:

/*
Settings for the softfilter: Maybe these should be adjustable from the
commandline, but Tolearance 10 and Filtersize 6 are good defaults.

- Tolerance: An absolute value (on a scale from 0 to 255), which
determines, if the colour diffence should be exposed to filtering or
not. This value needs to be bigger than the image noise peak to peak
value. All small stuctures in the image, that have a contrast of less
that this value are filtered down and might get lost.

- Filtersize: The array used for every pixel for filtering. The larger
this value is, the stronger the filter is, but also the longer will
filtering take. doubling this value will take four time longer for
filtering.
*/

const int Tolerance = 10;
const int Filtersize = 6;

#define MAX(a, b) ((a)>(b)?(a):(b))
#define MIN(a, b) ((a)<(b)?(a):(b))

/*
Softfilter is an advanced blur filter, that will not blindly soften everything
in the image, but will look at all pixels around the pixel to be modified, and
will only use these pixels, that have almost the same value.
By this simple rule, it will not soften down sharp edges, but only adjacent
pixels of almost the same color. The effect of this is dramatic. It can
eliminate almost all noise in large single colored areas of the image, without
significantly decreasing sharpness in other areas, where there is high
contrast.
The code is not really highly optimised, but it produces good results. If you
need speed badly, you can either not use it, or use some inline assembler.
I assume, you should be able to get quite a speedup from using assembler, but
I guess there is not more than 20% speedup possible by using C techniques.
Thomas Hieber (thieber@gmx.net)
*/

void softfilter(unsigned char* dest, unsigned char* src, int width, int height)
{
int refval, aktval, upperval, lowerval, numvalues, sum, rowindex;
int x, y, fx, fy, fy1, fy2, fx1, fx2;

for(y = 0; y < height; y++)
{
for(x = 0; x < width; x++)
{
refval = src[x+y*width];
upperval = refval + Tolerance;
lowerval = refval - Tolerance;

numvalues = 1;
sum = refval;

fy1 = MAX(y-Filtersize, 0);
fy2 = MIN(y+Filtersize+1, height);

for (fy = fy1; fy<fy2; fy++)
{
rowindex = fy*width;
fx1 = MAX(x-Filtersize, 0) + rowindex;
fx2 = MIN(x+Filtersize+1, width) + rowindex;

for (fx = fx1; fx<fx2; fx++)
{
aktval = src[fx];
if ((lowerval-aktval)*(upperval-aktval)<0)
{
numvalues ++;
sum += aktval;
}
} //for fx
} //for fy

dest[x+y*width] = sum/numvalues;
}
}
}


Regards,
-kwag
Reply With Quote
  #20  
11-16-2002, 01:48 PM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by kwag
This is not related to wavelets, but it might be worth a look.
NoMoSmooth already does this (as do TemporalSoften and SpatialSoften). This technique is especially useful in temporal smoothing because it completely eliminates ghosting.

Unfortunately it's also significantly slower than just doing a straight average because you have to check each pixel within the radius to see if it's inside the threshold.
Reply With Quote
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
Avisynth: Ads() a function using a masked denoising etc incredible Avisynth Scripting 97 10-19-2004 06:52 AM
Avisynth: funny denoising routines incredible Avisynth Scripting 44 11-15-2003 11:27 AM
Avisynth: Wavelet Noise Reduction? kwag Avisynth Scripting 98 09-23-2003 12:22 PM
Wavelet Noise Reduction for VirtualDub kwag Video Encoding and Conversion 3 03-15-2003 12:23 AM

Thread Tools



 
All times are GMT -5. The time now is 01:10 AM  —  vBulletin ę Jelsoft Enterprises Ltd