VideoHelp Forum
+ Reply to Thread
Results 1 to 9 of 9
Thread
  1. Hi everybody!

    I tested an avisynth script which gives me good results for what I'm seeking.

    I captured a 26 years old video tape last year (orginal format : PAL VHS captured to : PAL DVD (MPEG2 720x576 at : 25 fps)

    When I was capturing I noticed some coloured scratches lines. I found a very powerfull avisynth script on this very site (thanks to lollo) which removed 95% of those lines but there are some problems during motions scenes.

    Here is the script used :

    Code:
    #Source : https://forum.videohelp.com/threads/403553-Restoring-VHS-Tapes-with-Damage-(White-Horizontal-Lines-Colour-Distortion)#post2635329 
    
    #Script by : lollo
    
    # interlaced fields TFF
    # problem: horizontal stripe
    # solution: repair with FixRipsp2
    
    # Open AVI file
    video_org=AviSource("file.avi").convertToYV16(interlaced=true)
    
    
    # plugins directory where all the plugins are stored
    plugins_dir="C:\Program Files (x86)\AviSynth+\plugins+\"
    
        # FixRipsp2
    Import(plugins_dir + "FixRipsp2.avs")
        # RgTools
    loadPlugin(plugins_dir + "RgTools.dll")
        # DePanEstimate
    loadPlugin(plugins_dir + "DePanEstimate.dll")
        # FFTW
    loadPlugin(plugins_dir + "LoadDll32.dll")
    loadDll(plugins_dir + "fftw3.dll")
        # DePan
    loadPlugin(plugins_dir + "DePan.dll")
        # MaskTools2
    loadPlugin(plugins_dir + "masktools2.dll")
        # MVTools
    loadPlugin(plugins_dir + "mvtools2.dll")
    
    ### separate fields
    video_org_sep=video_org.AssumeTFF().separateFields()
    
    ### select even fields
    video_org_sep_even=SelectEven(video_org_sep)
    
    ### select odd fields
    video_org_sep_odd=SelectOdd(video_org_sep)
    
    ### repair
    video_org_sep_even_rep=video_org_sep_even.FixRipsp2().FixRipsp2()
    video_org_sep_odd_rep=video_org_sep_odd.FixRipsp2().FixRipsp2()
    
    ### interleave
    video_interleaved=interleave(video_org_sep_even_rep,video_org_sep_odd_rep)
    
    ### weave
    video_restored=video_interleaved.Weave()
    
    # Result :
    return(video_restored)
    
    # Original VS Result : (need to remove all the # below this line)
    #stackhorizontal(\
    #subtitle(video_org,"video_org",size=20,align=2),\
    #subtitle(video_restored,"video_restored",size=20,align=2)\
    #)
    And here is an example of the problem I'm facing. Original source on the left (video_org) , restored video on the right (video_restored). The dog in this scene is moving, and you can see that the scrathces lines are removed, but the black spots on the top of the dog's head are missing :

    What can I do in this script to soften the post processing? The main goal is to remove the scratches lines and to keep the blak spots.

    Unfortunatly I can't provide any video example, only this still image as the video is not mine.

    An other question is, what may cause those scratches? I think this comes fom the tape, the VCR did not do this on other tapes.

    Thanks a lot

    Please have a nice day

    Best regards
    Last edited by Hunk91; 21st Jan 2023 at 10:58.
    Quote Quote  
  2. I don't think you need such powerful script for this kind of errors
    Quote Quote  
  3. First, try calling fixripsp2 only once per field. For example:

    Code:
    video_org_sep_even_rep = video_org_sep_even.FixRipsp2()
    video_org_sep_odd_rep = video_org_sep_odd.FixRipsp2()
    If that doesn't work try using a different dirt remover like RemoveDirtMC which has a variable strength:

    Code:
    video_org_sep_even_rep = video_org_sep_even.RemoveDirtMC(20, false)
    video_org_sep_odd_rep = video_org_sep_odd..RemoveDirtMC(20, false)
    The higher the strength (20 in this example) the more dirt removal you get, but the higher the chance of other damage.

    RemoveDirtMC: https://forum.videohelp.com/threads/404337-Is-there-anything-I-can-do-to-cleanup-the-n...mc#post2644884

    For more detailed help upload a short sample of your source (not deinterlaced, not reencoded).
    Quote Quote  
  4. Captures & Restoration lollo's Avatar
    Join Date
    Jul 2018
    Location
    Italy
    Search Comp PM
    FixRipsp2() is a last resort, and quite destructive, especially applied twice.

    Start easy with a temproal degrain using a large temporal radius (tr=3,..,6), for example TemporalDegrain2 (the hope here is that the defect does not stay for many frames).

    If not effective, try RemoveDirtSMC, playing with its strength.

    If not effective, try SpotLess, eventually adding Delta Restore to put back removed details https://forum.doom9.org/showthread.php?p=1944703#post1944703
    In the posted link there are execellent ideas about recovering the deleted details.

    Edit: Sorry jagabo, I did not want to duplicate your suggestions, we were just writing at the same time and you arrived first.
    Last edited by lollo; 29th Mar 2022 at 04:21.
    Quote Quote  
  5. Thank you very much Jagabo and lollo for your help!

    First I tried the FixRipsp2 solution metionned but the deformation still occured.

    So I tried with RemoveDirtSMC and now the deformation is not occuring!

    I still have some white/bue/red lines appearing but they are reduced compare to the original.

    I will try to fine thune the settings in order to acheive what I'm looking for!

    Thanks a lot for your help!

    Please have a nice day

    best regards

    In order to help other people with a similar problem, here is the script I used :

    Code:
    #Source : https://forum.videohelp.com/threads/403553-Restoring-VHS-Tapes-with-Damage-(White-Horizontal-Lines-Colour-Distortion)#post2635329 
    
    #Script by : lollo
    
    # interlaced fields TFF
    # problem: horizontal stripe
    # solution: repair with FixRipsp2
    
    # Open AVI file
    video_org=AviSource("file.avi").convertToYV16(interlaced=true)
    
    
    # plugins directory where all the plugins are stored
    plugins_dir="C:\Program Files (x86)\AviSynth+\plugins+\"
    
        # FixRipsp2
    Import(plugins_dir + "FixRipsp2.avs")
        # RgTools
    loadPlugin(plugins_dir + "RgTools.dll")
        # DePanEstimate
    loadPlugin(plugins_dir + "DePanEstimate.dll")
        # FFTW
    loadPlugin(plugins_dir + "LoadDll32.dll")
    loadDll(plugins_dir + "fftw3.dll")
        # DePan
    loadPlugin(plugins_dir + "DePan.dll")
        # MaskTools2
    loadPlugin(plugins_dir + "masktools2.dll")
        # MVTools
    loadPlugin(plugins_dir + "mvtools2.dll")
    
    ### separate fields
    video_org_sep=video_org.AssumeTFF().separateFields()
    
    ### select even fields
    video_org_sep_even=SelectEven(video_org_sep)
    
    ### select odd fields
    video_org_sep_odd=SelectOdd(video_org_sep)
    
    ### Original repair but too much deformations on dynamic scenes
    #video_org_sep_even_rep=video_org_sep_even.FixRipsp2().FixRipsp2()
    #video_org_sep_odd_rep=video_org_sep_odd.FixRipsp2().FixRipsp2()
    
    ### repair with RemoveDirtSMC, updated by jagabo and lollo : https://forum.videohelp.com/threads/405254-Scratches-line-removed-but-details-disapeared-on-motion-scenes#post2652521
    video_org_sep_even_rep = video_org_sep_even.RemoveDirtMC(20, false)
    video_org_sep_odd_rep = video_org_sep_odd.RemoveDirtMC(20, false)
    
    ### interleave
    video_interleaved=interleave(video_org_sep_even_rep,video_org_sep_odd_rep)
    
    ### weave
    video_restored=video_interleaved.Weave()
    
    # Result :
    return(video_restored)
    
    # Original VS Result : (need to remove all the # below this line)
    #stackhorizontal(\
    #subtitle(video_org,"video_org",size=20,align=2),\
    #subtitle(video_restored,"video_restored",size=20,align=2)\
    #)
    Quote Quote  
  6. Captures & Restoration lollo's Avatar
    Join Date
    Jul 2018
    Location
    Italy
    Search Comp PM
    RemoveDirtSMC is different from RemoveDirtMC; choose the one performing better
    Quote Quote  
  7. Originally Posted by Hunk91 View Post
    I still have some white/bue/red lines appearing but they are reduced compare to the original.
    You can use stronger settings and an alpha mask to get rid of more "dirt" while protecting other areas. Using the single frame from your sample image:

    Original image:
    Image
    [Attachment 64055 - Click to enlarge]


    Alpha mask of red and purple areas:
    Image
    [Attachment 64056 - Click to enlarge]


    Original image with red and purple areas replaced with green:
    Image
    [Attachment 64058 - Click to enlarge]


    I used green for "fixed" areas just so you could see what areas were changed and what areas weren't (without a video sample I can't really fix those areas). With the original video you would just use very strong RemoveDirtMC settings -- settings that are so strong they damage other parts of the image, but since the areas are protected by the mask the damage isn't passed through to the final output.

    Code:
    ImageSource("scratches.png", start=0, end=23, fps=23.976) 
    Crop(102, 56, 720, 576)
    ConvertToYV24()
    
    # build a mask of moderately saturated red areas with MaskHS
    redmask = MaskHS(StartHue=80, EndHue=125, MinSat=20, MaxSat=150).ConvertToYV24().mt_expand.Blur(1.4).GreyScale()
    
    # build a mask of moderately saturated purple areas with MaskHS
    purplemask = MaskHS(StartHue=0, EndHue=20, MinSat=20, MaxSat=150).ConvertToYV24().mt_expand.Blur(1.4).GreyScale()
    
    # add the red and purple masks together
    rpmask Overlay(redmask, purplemask, mode="add")
    
    # build an alternate version of the video that's all shades of green
    alt = ColorYUV(off_u=-256, off_v=-256).ColorYUV(off_u=100, off_v=100)
    
    # replace all the red and purple areas with the green video
    Overlay(last, alt, mask=rpmask)
    I know you also have some white streaks so you would have to add those areas to the alpha mask. But again, without a sample that shows those areas I can't really show how it would work. This is why it's important to provide video samples.
    Quote Quote  
  8. Originally Posted by lollo View Post
    RemoveDirtSMC is different from RemoveDirtMC; choose the one performing better
    Oops! Sorry for the typo, my brain made a fusion of RemoveDirtMC and SMDegrain. I didn't know that RemoveDirtSMC exists. i will check that in order to know what it can do


    Originally Posted by jagabo View Post

    Code:
    ImageSource("scratches.png", start=0, end=23, fps=23.976) 
    Crop(102, 56, 720, 576)
    ConvertToYV24()
    
    # build a mask of moderately saturated red areas with MaskHS
    redmask = MaskHS(StartHue=80, EndHue=125, MinSat=20, MaxSat=150).ConvertToYV24().mt_expand.Blur(1.4).GreyScale()
    
    # build a mask of moderately saturated purple areas with MaskHS
    purplemask = MaskHS(StartHue=0, EndHue=20, MinSat=20, MaxSat=150).ConvertToYV24().mt_expand.Blur(1.4).GreyScale()
    
    # add the red and purple masks together
    rpmask Overlay(redmask, purplemask, mode="add")
    
    # build an alternate version of the video that's all shades of green
    alt = ColorYUV(off_u=-256, off_v=-256).ColorYUV(off_u=100, off_v=100)
    
    # replace all the red and purple areas with the green video
    Overlay(last, alt, mask=rpmask)
    I know you also have some white streaks so you would have to add those areas to the alpha mask. But again, without a sample that shows those areas I can't really show how it would work. This is why it's important to provide video samples.
    Thanks a lot Jagabo! I will try this script and let you know about the results!

    Unfortunatly I can't post any video clip from the video as I'm not the owner of it. I asked to the owner leting him know that this will help to improve the quality of the restoration but he is very strict about that and I can't go against his will. I'm sure you could have done wonders with a clip!
    Quote Quote  
  9. You will probably have to tune the MaskHS settings. Here's a little help:

    https://forum.videohelp.com/threads/403141-How-to-use-AviSynth-to-find-duplicate-video...e4#post2632583
    http://avisynth.nl/index.php/MaskHS

    The general idea is to set the ranges wide enough to cover the areas you are interested in, but not so wide that other parts of the picture aren't included too. Of course, if other parts of the picture are the same color as the streaks the will be included too. That may or may not be a problem. If it is you may be other to add other restrictions (brightness, horizontal lines only, particular ranges of frames, etc.).
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!