Log in

View Full Version : Remove some static dot


lisztfr9
30th May 2014, 16:06
Just for learning purpose i wanted to do some tests, removing an unwanted static artifact. But overlay is somewhat tricky to control :

1) You rely on levels ().
2) Once a mask is build with Mask(), levels() will not show any changes, even if it' produces some...

See with this test image :

http://img4.hostingpics.net/pics/310043dot2.png



# LOAD PLUGIN :

# LoadPlugin(many)

a1 = ImageSource("dot_2.png").ConvertToRGB32

#overlay :
a2 = crop(a1, 61, 59, -547, -389) #.AddBorders(1, 1, 1, 1, $000000)

# initializing :
over = a2.Levels(0, 1.0, 255, 0, 255)
# mask_clip = a2.Levels(143, 1.0, 199, 255, 0) , testing contrast

mask_clip = Mask(a2, a2.Levels(54, 1.0, 196, 0, 255)).invert()


# effect on dot :
r1 = Overlay(a1, over, y=59, x=61, mask=showalpha(mask_clip), mode="add", opacity=1)

# no dot underneath :
r2 = Overlay(r1, over, y=59, x=(61 + 64), mask=showalpha(mask_clip), mode="blend", opacity=1)

# overlay without mask :
r3 = Overlay(r2, over, y=59, x=(61 + 128), mode="blend", opacity=1)

# mask
r4 = Overlay(r3, mask_clip, y=(59 + 164), x=61, mode="blend")


r4 = crop(r4, 0, 0, -320, -0).AddBorders(0, 0, 8, 0, $FFFFFF)
a1 = crop(a1, 0, 0, -320, -0) # original

StackHorizontal(r4, a1)



The dot was removed, but "human controlled"; I guess with subtract() i could fine tune the result. Thanks for reading, L

lisztfr9
31st May 2014, 19:27
This test involves the same sample image as above...

There is a moving dot, and a mask is overlaid as a "denoiser", the coincidence with the moving dot is delegate to MVtools, i don't believe that it's working so please, comment !




# LOAD PLUGIN :

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\ac3source.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\NicAudio.dll")

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\depanestimate.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\depan.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\FluxSmooth.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\DeGrainMedian.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\mvtools2.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\FFT3DFilter.dll")


# a1 = ImageSource("dot_1.png").ConvertToRGB32
a1 = ImageSource("dot_2.png").Trim(0,399).ConvertToRGB32

# overlay :
a2 = crop(a1, 61, 59, -547, -389)#.AddBorders(1, 1, 1, 1, $000000)

# layer test :
# Layer(a1, a2, x=0, y=0, op="add")

# initializing :
a2 = a2.Levels(0, 1.0, 255, 0, 255)
# mask_clip = a2.Levels(143, 1.0, 199, 255, 0)
# approximation
mask_clip = Mask(a2, a2.Greyscale.Levels(54, 1.0, 196, 0, 255)).invert()


# Overlay(a1, a2, mask=ShowAlpha(mask_clip), y=59, x=61, mode="add", ignore_conditional=true, opacity=1)
# used as "denoiser"

# nasty dot :
Overlay(a1, a2, y=0, x=0, mode="blend", opacity=1)
ConditionalReader("C:\Program Files\AviSynth 2.5\Examples\test\xoffset.txt", "ol_x_offset", false)
ConditionalReader("C:\Program Files\AviSynth 2.5\Examples\test\yoffset.txt", "ol_y_offset", false)

ConvertToYV12()

# Denoise

super = MSuper()
backward_vectors = MAnalyse(super, isb = true)
forward_vectors = MAnalyse(super, isb = false)
forward_compensation = MFlow(super, forward_vectors, thSCD1=500) # or use MCompensate
backward_compensation = MFlow(super, backward_vectors, thSCD1=500)
# create interleaved 3 frames sequences
interleave(forward_compensation, last, backward_compensation)

# prefered "denoiser" = overlay
ConvertToRGB()
Overlay(a1, a2, mask=ShowAlpha(mask_clip), y=59, x=61, mode="add", ignore_conditional=true, opacity=1)

selectevery(3,1) # return filtered central (not-compensated) frames only

last



The ConditionalReader uses following files :

xoffset.txt

Type int
Default 61

R 0 100 61
I 100 200 61 250
R 200 300 250
I 300 400 250 400

yoffset.txt

Type int
Default 59

R 0 100 59
I 100 200 59 350
R 200 300 350
I 300 400 350 40


It seems to work ? If i disable the mask, the dot appears again, sliding along it's coordinates... hard to believe, and what happens to the static dot ? that's worrying me a lot... Thanks, L

lisztfr9
31st May 2014, 21:17
Less bugs, and showing it doesn't work as expected ....



# LOAD PLUGIN :

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\ac3source.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\NicAudio.dll")

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\depanestimate.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\depan.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\FluxSmooth.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\DeGrainMedian.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\mvtools2.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\FFT3DFilter.dll")


# a1 = ImageSource("dot_1.png").ConvertToRGB32
a1 = ImageSource("dot_2.png").Trim(0,399).ConvertToRGB32

#overlay :
a2 = crop(a1, 61, 59, -547, -389)#.AddBorders(1, 1, 1, 1, $000000)

# layer test :
# Layer(a1, a2, x=0, y=0, op="add")

# initializing :
a2 = a2.Levels(0, 1.0, 255, 0, 255)
# mask_clip = a2.Levels(143, 1.0, 199, 255, 0)
mask_clip = Mask(a2, a2.Greyscale.Levels(54, 1.0, 196, 0, 255)).invert()

# Overlay(a1, a2, mask=ShowAlpha(mask_clip), y=59, x=61, mode="add", ignore_conditional=true, opacity=1)

# overlay without mask :
Overlay(a1, a2, y=59, x=(61 + 128), mode="blend", ignore_conditional=true, opacity=1)

a1 = last

# nasty dot :
Overlay(a1, a2, y=0, x=0, mode="blend", opacity=1)
ConditionalReader("C:\Program Files\AviSynth 2.5\Examples\test\xoffset.txt", "ol_x_offset", false)
ConditionalReader("C:\Program Files\AviSynth 2.5\Examples\test\yoffset.txt", "ol_y_offset", false)

test = last

ConvertToYV12()

last

# Denoise

super = MSuper()
backward_vectors = MAnalyse(super, isb = true)
forward_vectors = MAnalyse(super, isb = false)

forward_compensation = MFlow(super, forward_vectors, thSCD1=500) # or use MCompensate
backward_compensation = MFlow(super, backward_vectors, thSCD1=500)
# create interleaved 3 frames sequences
interleave(forward_compensation, last, backward_compensation)

# prefered "denoiser" = overlay
ConvertToRGB()
Overlay(last, a2, mask=ShowAlpha(mask_clip), y=59, x=61, mode="add", ignore_conditional=true, opacity=1)

selectevery(3,1) # return filtered central (not-compensated) frames only

W=320
H=240

last = last.BilinearResize(W, H)
test = test.BilinearResize(W, H)

StackHorizontal(last, test)

johnmeyer
31st May 2014, 21:30
It sounds like you are using AVISynth to do this because you want the challenge of doing it that way. However, if you simply want to remove a fixed spot from a video, here's a short tutorial I created several years ago that uses VirtualDub to accomplish exactly that task:

Tutorial on Delogo Filter for Virtualdub (http://www.youtube.com/watch?v=Z12TutFSg8c)

This approach is a lot easier to do than using an AVISynth script.

lisztfr9
1st June 2014, 14:47
@ johnmeyer

Thank you johnmeyer, i will read your tuto soon. Ok i see it's about Delogo, right, but in case you have some changing pattern instead of a logo ? You need to create the overlay sequence at the fly. So, there is merge, or overlay, the later one needs RGB (drawback), but has many operation modes, so imho, overlay is a Swiss knife, and merge a universal tool. Anyway i made a lot flux errors above.

L

johnmeyer
2nd June 2014, 03:03
Well, if you have a changing pattern, then you'll need motion tracking, or something similar. I don't think AVISynth offers motion tracking, and without a GUI interface, I don't know how it would work, even if some plugin for tracking objects did exist. Removing an object, or blurring an object (like someone's face) usually requires something like After Effects.