I've had a lot of questions about how I did some of my recent logo removal using the DVD source, so I thought I'd write a guide to share what I've learned in case anybody else wants to try it out…
As you'll see, it's time-consuming, and a lot of things have to be just right in order for this kind of restoration to even be possible. I've had really good luck on couple of Disney films I've done, but your mileage may vary on other sources. For this example, I'll use The Little Mermaid, since it worked out particularly nicely, and a lot of you have seen it (or at least a sample or screens).
This is a pretty advanced technique, so I'll assume if you're reading this you're fairly good with AviSynth and AVSP (or the like). So with that, here's how you do it…
The first thing you'll have to do is frame-align the HDTV source with the DVD. This part is absolutely critical, and if you can't do it perfectly (i.e. the sources are different cuts), you can stop here. It won't work. If you're off by even 1 frame, you'll start seeing the outline of the logo during motion and a silhouette of the logo on scene changes. You can, of course, get creative with Trim(), DeleteFrame() and DuplicateFrame() if the sources are only off by a couple of frames, but be careful that everything continues to line up all the way through.
The second thing you'll have to do is pixel-match the two sources so that everything within each frame lines up perfectly. And when I say perfectly, I mean within 1 pixel at the HDTV source resolution. Any more than that, and you'll see an outline of the logo during motion. Use your choice of Resize() functions and AddBorders() to get everything lined up. If the framing of the two sources isn't consistent from scene to scene (for example if one is P&S), you may as well stop. It probably won't work out.
Of course, it's easier to match the frames if the pixels are lined up, so I usually take care of both of those steps at the same time. Here's the script for my sources after these two steps
Цитата:
MPEG2Source("c:\LITTLE_MERMAID\VTS_01.d2v")
TFM(pp=0).TDecimate()
dvd=Trim(30,379) + Trim(487,82117) + Trim(82138,0)
hdtv=DGSource("c:\The Little Mermaid 1989 1080p HDTV DD2.0 h264.dgi").Trim(7,0).AssumeFPS("ntsc_film")
upscale=dvd.ConvertToRGB().Spline36Resize(1914,1060,1,0,-1,-2).AddBorders(2,15,4,5).ConvertToYV12()
Interleave(hdtv,upscale)
Note that I converted the DVD source to RGB here to allow me to use AddBorders() with an odd number of pixels. The same would apply for Resize(). If you have to do that to get within 1 pixel, do it. Remember, you can't be off by more than 1.
Here's the result so far. Note that although the DVD is considerably less sharp and has ringing and different colors and all that, it doesn't matter. Those, we can fix. The frame-alignment and pixel-alignment are all down to the source , though. If everything matches on those, we're good to go.
HDTV
DVD
Next, you'll want to address the color issues. Most of the difference will probably come from the difference in standard HD vs SD color spaces. You can fix this with ColorMatrix(), or since I'm already converting to RGB for the resize, I can go ahead and address it there.
Цитата:
upscale=dvd.ConvertToRGB("PC.601").Spline36Resize(1914,1060,1,0,-1,-2).AddBorders(2,15,4,5).ConvertToYV12(matrix="PC.709")
PC.601->PC.709
That has gotten the sources really close, but you may want to do same additional tweaking. Again, since I've already converted to RGB for the both the resize and color space change, it's easy to throw in an AdjustRGB() to get them even closer. This is what I ended up with.
Цитата:
upscale=dvd.ConvertToRGB("PC.601").RGBAdjust(g=1.003,b=0.995,r=0.99).Spline36Resize(1914,1060,1,0,-1,-2).AddBorders(2,15,4,5).ConvertToYV12(matrix="PC.709").ColorYUV(gamma_y=1)
I won't bother with screens at this point since it's so close you can't see it on those anyway. That does, however, emphasize the fact that at each step, it's important to check your results throughout the length of the source, especially in different light levels and such. Most of the tweaking I did was to correct white levels.
Now that your sources are frame-matched, pixel-matched, and color-matched, you can start to think about getting rid of that logo. For the rest of the work, I'll crop down to just the logo area. That will improve performance since we still have some filtering to do. Make sure when you crop, you leave a healthy amount of margin around the logo since you'll want to feather in the DVD with the HDTV to avoid a harsh outline. And you'll probably want to make sure you crop to a mod-4 width since some filters won't work otherwise. I'm going with a 360x360 area.
Цитата:
hdtvc=hdtv.Crop(76,720,-1484,0)
upscalec=upscale.Crop(76,720,-1484,0)
Interleave(hdtvc,upscalec)
HDTV -------------->DVD
Next, you'll want to do whatever filtering you feel is necessary to make the DVD match the HDTV source as closely as you can. In this example, I want to de-ring (and denoise) the DVD and sharpen it a bit. Also remember that if you'll be scaling down to 720p from a 1080 source, that will hide some of the difference, so don't worry if they don't match exactly. Here's what I used for filtering, and the result.
Цитата:
upscalecf=upscalec.Overlay(StackVertical(upscalec.Crop(0,346,0,-8), upscalec.Crop(0,346,0,-8)).Blur(1.50),0,348).HQDering(220,0,Deen(upscalec,"a2d",4,12,12)).FastLineDarken().LSFMod(strength=192,SMode=2,SMethod=3).TemporalSoften(1,2,4).Deen("a2d",1,4,4).AddGrainC(0.9).AddGrainC(0.9)
HDTV-------------> Filtered
Again, it's not perfect, but it doesn't have to be. It's close enough.
Now that you have something that looks better than the logo and that will blend well, it's time to replace the logo with it. The last thing you'll need is a mask that separates the logo from the rest of the cropped area. I used Photoshop to modify a fully black frame with the logo on it to create the mask. Make the logo itself completely white and leave the rest of the frame black. Then expand the logo by a couple of pixels to make sure the edges are completely covered (even when compression artifacts smudge it) and feather it out so you get a nice blend. My mask for this logo looks like this:
Then you can use the Mask() and Layer() functions to replace the logo. Mask() creates the mask in the alpha channel of an RGB32 clip, so you'll need to convert everything to RGB32 before you call Mask() and Layer().
Цитата:
maskc=ImageSource("c:\dismask.png").Crop(76,720,-1484,0).ConvertToRGB32()
hdtvc.ConvertToRGB32().Layer(upscalecf.ConvertToRGB32().Mask(maskc)).ConvertToYV12()
Then, just overlay that back on the HDTV clip in the same spot it was cropped from
Цитата:
hdtv.Overlay(last,76,720).Trim(0,112110) + hdtv.Trim(112111,118667)
It looks good but will look even better after scaling to 720p.
And there you have it… ugly logo destroyed.