Log in

View Full Version : Filter for Removing Comp.Artifacts and Noise


krieger2005
12th May 2004, 19:02
Hi,

i'm on scripting a function for removing Compression-Artifacts and Noise. I found, as i think, a good variant to do that and want to ask you for your deliverance and proposal.

Here the idea:

1. Creating a blured Movie of the Noise Movie (A movie, where the noise is away but the image is too blured)
2. creating a Mask of areas, where noise is (or Artifacts)
3. Merge the blured Movie into the original-Movie

Script updated: 13.05.2004, 00:26, GMT +1:00

Here my script as long

Function rem(clip c1, clip c2, int b1, int b2, bool debugB, int d1, int d2, bool debugD){
c1

green=ConvertToRGB32.RGBAdjust(0.5,1,0.5,0).ConvertToYV12
white=BlankClip(length=framecount, width=width, height=height,
\ pixel_type="YV12",fps=25,color=$FFFFFF)
diff=YV12Subtract(last,Unfilter(110,110))
maskB=diff.Levels(b1,1,b2,255,235,false).YV12LUT(Yexpr="x 236 < 0 x ?")
bright= debugB == true ? green.MaskedMerge(white,maskB) :
\MaskedMerge(c2, maskB)

bright
green=ConvertToRGB32.RGBAdjust(0.5,1,0.5,0).ConvertToYV12

maskD=diff.Levels(d1,1,d2,75,155,false).YV12LUT(Yexpr="x 76 < 0 x ?")
dark= debugD == true ? green.MaskedMerge(white,maskD) :
\ MaskedMerge(c2, maskD)

return dark
}


Here another version:

function rem(clip c1, clip c2, int b1, int b2, bool debugB, int d1, int d2, bool debugD){
c1
c1Invert=c1.ConvertToRGB32.invert.ConvertToYV12
diff=Subtract(Unfilter(110,110))
maskB=diff.YV12LUT(Yexpr="x "+String(b1)+" < x "+String(b2)+" > | 0 255 ?")
bright="overlay(c2,mask=maskB)"

maskD=diff.YV12LUT(Yexpr="x "+String(d1)+" < x "+String(d2)+" > | 0 255 ?")
dark="overlay(c2,mask=maskD)"

debug = debugB == true ? "maskB" : debugD == true ? "maskD" : ""
out = debug != "" ? "Stackvertical("+bright+"."+dark+", MaskedMerge(c1Invert, "+debug+"))" :
\ bright+"."+dark

return eval(out)
}


I try you to explain:
1.
The First step is to generate a movie, which has no artifacts:
For Exaple:

sauber=ConvertToRGB32._2DClean(0,18,2,2).ConvertToYV12.UnDot.Blur(1).Unfilter(40,40)


2.
In the second step i try to create a mask, where i have highlighted the Artifacts and Noise. To do that i subtract the original-movie from a Oversharped Movie. I get colors which are mostly about 127 (127 means the Colorvalue in Grey). This are the areas, which are alike in the original and the oversharped movie. All areas with different color that 127 (plus/minus X) are Artifacts or Noise (so my theory).
In my Function i make a mask for bright-Noise and one for dark noise. d1,d2 is the Dark Noise (which must be from 127-255), and b1,b2 are Boundaries for Bright Noise (which must be between 0-127).
I build in debugviews for showing bright-noise and dark-noise (debugB and debugD). For my testmovie i use this paramteres:

rem(last,sauber,100,110,false,140,145,false)

Here is the Bright-Noise between 100 and 110 and Dark-Noise is between 140 and 145.
3.
... MaskedMerge


So, what you think about?
Try it!!


Here a sample-capture:
above: After Filter-usage
below: original
http://freehost11.websamba.com/krieger2005/sample.jpg

krieger2005
18th May 2004, 00:08
Do you think this way is bad?

Sorry, but i want to know your meanings...

DarkNite
18th May 2004, 09:42
I found this method to be surprisingly effective on the sports capture I tested it with. I do have a question though.

Is converting to RGB32 really necessary?

krieger2005
18th May 2004, 12:52
Do you mean:
green=ConvertToRGB32.RGBAdjust(0.5,1,0.5,0).ConvertToYV12

or
sauber=ConvertToRGB32._2DClean(0,18,2,2).ConvertToYV12.UnDot.Blur(1).Unfilter(40,40)
?

In first case i use green as a mask. And as long i use RGBAdjust for that i must (correct me if i'm wrong) use ConverttoRGB32. But this were only used when debugB or debugD is "true". The normal Output is YV12.
In the second case "_2DClean" is a VirtualDub filter so i must convert to RGB. But this is your deal how to clean the source image. I try as long, as my image seems to be clean and than use my function above...

Till now i modified the Function and think i accelerate the Executiontime.

DarkNite
19th May 2004, 00:34
Thank you for the clear and timely response.

Just for informational purposes: _2DClean is also available as an AviSynth (2.x or 2.5x) plugin, and for YUY2 (_2DCleanYUY2).

I'll try the other version of the script after tonight's capture is finished.

Abaddon666
19th May 2004, 06:04
Wow, this looks quite interesting. I'll give it a try as soon as my computer works again.

Greetz,
Abaddon666