VideoHelp Forum




+ Reply to Thread
Page 4 of 4
FirstFirst ... 2 3 4
Results 91 to 109 of 109
  1. Sorry, I forgot that I had included coring=false: levels(0,1,255,16,235,coring=false):

    SourceRGB image:
    Click image for larger version

Name:	levels17.png
Views:	1049
Size:	1.5 KB
ID:	1531

    ImageSource("levels17.png", start=0, end=7200, fps=23.976)
    ConvertToYUY2(matrix="PC.601")
    v1=VideoScope("bottom").Subtitle("after ConvertToYUY2()")
    v2=Levels(0,1,255,16,235,coring=false).VideoScope( "bottom").Subtitle("after levels()")
    stackVertical(v1,v2).ConvertToRGB(matrix="PC.601")
    Click image for larger version

Name:	after.png
Views:	830
Size:	12.7 KB
ID:	1532

    I corrected the earlier post.
    Last edited by jagabo; 25th Apr 2010 at 11:00.
    Quote Quote  
  2. by increasing the gamma, I get a shaper edge. But some lines remains dark from the beginning to the end..

    Lets take an example:

    original:
    Click image for larger version

Name:	bad_line_original.jpg
Views:	1208
Size:	1.8 KB
ID:	1537

    after setting the black to the average luma of the 8 first pixels and the white to the average luma of the 8 last pixels:
    Click image for larger version

Name:	bad_line.jpg
Views:	1205
Size:	2.7 KB
ID:	1536

    And I used a gamma with a very high value (1000) but there is nothing to do.. I cannot get any bright pixel at the right.. And if I display the average luma, I get 16.5 for the first 8px and 25.25 for the last 8px. So by increasing the gamma to a certain point, I should be able to get some white pixel, shouldn't I ?
    Last edited by mathmax; 25th Apr 2010 at 14:07.
    Quote Quote  
  3. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by mathmax View Post
    I cannot get any bright pixel at the right.. And if I display the average luma, I get 16.5 for the first 8px and 25.25 for the last 8px. So by increasing the gamma to a certain point, I should be able to get some white pixel, shouldn't I ?
    You should be using Levels(black, gamma, white, 0, 255, coring=false), or perhaps Levels(black, gamma, white, 16, 235, coring=false). The coring=false is needed so that the input pixels are not scaled from [16, 235] to [0, 255] before the levels conversion itself is performed.
    Quote Quote  
  4. yes. And I have to scale the image from [16, 235] to [0, 255] before getting average luma from the left and the right..
    So the final script is:

    Code:
    ImageSource("image.bmp")
    
    PointResize(width, height * 2)
    ConvertToYV12()
    Levels(16, 1, 235, 0, 255, coring=false)
    ProcessLine(last, 0)
    PointResize(width, height / 2)
    
    function ProcessLine(c, int n)
    {
        crop = c.Crop(4,n*2,28,2)
        newcrop = ScriptClip(crop, "
               black = int(AverageLuma(Crop(0,0,8,2))) #get the average luma of the left pixels
               white = int(AverageLuma(Crop(20,0,8,2))) #get the average luma of the right pixels
               margin = (white - black)/3
               Levels(black + margin, 2, white - margin/2, 0, 255, coring=false) #adjust the level to make the left real black and right real white. 
        ")
    
        Overlay(c, newcrop, 4, n*2)
        
        return (n < 239) ?  ProcessLine(last, n + 1) : c
    }
    In order to get the most relevant result possible, I made the following changes:

    - increase the gamma value from 1 to 2: at the limit of a scan line the pixels become gradually brighter. Setting a higher gamma should crush the luma of these pixels and sharpen the edge. I was even thinking of changing the gamma value according to the white value.. but I finally see no relevant argument to do this.

    - the black has a lot of noise.. so some pixels are brighter. In order to keep them black, I raised the black to black + margin where margin = (white - black)/3.

    These value are arbitrarily chosen according to my feeling. Any comments or other ideas would be greatly welcome.

    Now, I'm facing a new problem.. when performing on a video, the script is very slow.. Any idea to make it more efficient?
    Quote Quote  
  5. Try a low pass filter to reduce the noise and reducing the image to grayscale. You only need to do that on your test strip of course. And instead of Levels() try using ColorYUV().
    Last edited by jagabo; 25th Apr 2010 at 20:31.
    Quote Quote  
  6. Thank you for these advices. I would need some explanations.

    Try a low pass filter to reduce the noise and reducing the image to grayscale.
    Should I apply this filter in the black strip only or in all the "crop" clip (28px)? It seems risky to remove the noise because you're loosing information.. or maybe you want to apply this filter after adjusting the levels?

    And instead of Levels() try using ColorYUV().
    Why? To increase the speed of my script or to get a better result? The color of the noised pixels is sometimes the same as the color of the pixels of the scan lines. Whereas the luma is really different between the black strip and the scan lines. It seems more random to work with all the colors rather than just the brightness.. but I'm certainly missing something, am I?

    Any idea to make the script quicker?
    Quote Quote  
  7. I'm just throwing out ideas. But you're right regarding grayscale -- if you're only working only with Y it doesn't matter.
    Quote Quote  
  8. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by mathmax View Post
    Now, I'm facing a new problem.. when performing on a video, the script is very slow.. Any idea to make it more efficient?
    Processing with ScriptClip is inherently slower, since the 'run-time' script must be parsed and evaluated afresh for every frame. Also, working with individual scanlines (or pairs as here) inevitably slows things down, as you have 240 chained invocations of your ProcessLine function.

    One way to speed it up is to use StackVertical instead of Overlay to build up the result, with just a single Overlay at the end. Change ProcessLine to construct just the vertical strip to be replaced, as follows:
    Code:
    function ProcessLine(clip c, int n)
    {
        crop = c.Crop(4,n*2,28,2)
        newcrop = ScriptClip(crop, "
               black = int(AverageLuma(Crop(0,0,8,2))) #get the average luma of the left pixels
               white = int(AverageLuma(Crop(20,0,8,2))) #get the average luma of the right pixels
               margin = (white - black)/3
               Levels(black + margin, 2, white - margin/2, 0, 255, coring=false) #adjust the level to make the left real black and right real white. 
        ")
    
        return (n < 239) ?  StackVertical(newcrop, ProcessLine(c, n + 1)) : newcrop
    }
    and replace the outer call ProcessLine(last, 0) by
    Overlay(last, ProcessLine(last, 0), 4, 0)
    [or simply Overlay(ProcessLine(0), 4, 0)]
    Quote Quote  
  9. ya it's faster

    And is there any other tricks to speed things up even more? Should I necessarily use a runtime function? Maybe it's possible pre-build ScriptClip().. or the full script.

    http://www.softpedia.com/get/Multimedia/Video/Other-VIDEO-Tools/AVISynthesizer.shtml
    Last edited by mathmax; 26th Apr 2010 at 09:43.
    Quote Quote  
  10. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Short of writing your own customised plugin to do the job, I don't think there's much more you can do to speed it up, as the slowness is inherent in the problem. ScriptClip is needed, since the processing is different for each frame, and processing by scanline inevitably requires taking each frame apart and putting it back together again.

    Since Crop and StackHorizontal are relatively fast operations, a minor change would be to replace the outer Overlay by a StackHorizontal of left part (pixels 0-3), new middle (4-31), and right part (32-end), but since that's only done once per frame, the savings will not be so great.

    What I mean is replace Overlay(ProcessLine(0), 4, 0) by
    StackHorizontal(Crop(0, 0, 4, 0), ProcessLine(0), Crop(32, 0, 0, 0))

    I'm not familiar with AviSynthesizer, but I doubt if it could generate faster scripts than hand-crafted ones.
    Last edited by Gavino; 26th Apr 2010 at 14:31. Reason: 'middle' part is pixels 4-31
    Quote Quote  
  11. ok. Thank you. The script is not very fast but it's acceptable..

    Now, I've to detect the average position of the left edge. And the "crop" clip must be centered around this limit in order to be sure the eight pixels from the left are in the black strip and the 8 last pixels are in the scan lines.
    Here you can see that there are significant differences between the frames:

    Click image for larger version

Name:	00040.jpg
Views:	855
Size:	77.0 KB
ID:	1563
    Click image for larger version

Name:	00019.jpg
Views:	803
Size:	88.6 KB
ID:	1564

    How would you establish the average position of this limit?
    Quote Quote  
  12. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by mathmax View Post
    How would you establish the average position of this limit?
    The simplest thing would be to do it by eye, stepping through a representative range of frames one at a time in an editor. Note - AvsP will show you the coordinates of the pixel under the mouse pointer.

    One way to do it in a script might be to take the AverageLuma of successively wider vertical strips until the value is greater than some threshold. I haven't fully thought this through and I'll leave you to work out the details, if indeed it's practical at all.

    BTW there was an error in my last post, now corrected. The replaced vertical strip is of course 28 pixels wide, not 8 as I had there.
    Quote Quote  
  13. The problem is how to store the averageluma value of a vertical strip in a variable since the function local variables do not exist when the run-time script is evaluated..
    Quote Quote  
  14. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Perhaps a global variable could be used?
    If you have an outline script in mind, post it here and I will see if and how it might be made to work.
    Quote Quote  
  15. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Thinking further about this, I think the script logic needs to be something like:
    Code:
    for each frame:
      determine edge position
      for each scanline:
        fix levels for pixels around this edge
      replace edge pixels
    So in outline the script would be:
    Code:
    global thresh = ??? # luma threshold to determine edge
    
    function FindEdge(clip c, int current_frame, int x) {
      (x >= 50 || AverageLuma(c.Crop(2, 0, x-2, 0)) > thresh) ? x : FindEdge(c, current_frame, x+2)
    }
    
    function ProcessLine(clip c, int current_frame, int edge, int n) {
      c.Crop(edge-14,n*2,28,2) # get section around edge for scanline n
      black = int(AverageLuma(Crop(0,0,8,2))) #get the average luma of the left pixels
      white = int(AverageLuma(Crop(20,0,8,2))) #get the average luma of the right pixels
      margin = (white - black)/3
      newcrop = Levels(black + margin, 2, white - margin/2, 0, 255, coring=false) #adjust the level to make the left real black and right real white. 
    
      return (n < 239) ?  StackVertical(newcrop, ProcessLine(c, current_frame, edge, n + 1)) : newcrop
    }
    
    ...
    
    ScriptClip("""
      edge = FindEdge(current_frame, 16)
      fixed = ProcessLine(current_frame, edge, 0)
      StackHorizontal(Crop(0, 0, edge-14, 0), fixed, Crop(edge+14, 0, 0, 0))
    """)
    This assumes the edge will be somewhere between 16 and 50 pixels from the left (lower limit necessary to avoid negative Crop offsets).
    Passing current_frame to the functions is a hack to allow AverageLuma to work inside a function - this could be avoided using GRunT.
    The recursions could be replaced by for/while loops using GScript.
    Quote Quote  
  16. Thank you very much for this. And sorry for my late answer.. I wasn't at home the last days.

    By taking a strip of 36px width and setting the black with the 6px at the left and the white with the 6px at the right, I get satisfying result for all frames without having to detect the average position of the edge.
    Now I'll try your script to see if it's better.

    I would like to do the same with the right edges of the frames (between position 684 and 720) but I cannot use StackVertical() because it'll stack the strip at the left hand side. I could use overlay()... but it'll be slower. How would you get around this problem?
    Quote Quote  
  17. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by mathmax View Post
    I would like to do the same with the right edges of the frames (between position 684 and 720) but I cannot use StackVertical() because it'll stack the strip at the left hand side.
    I don't see the problem, the logic is the same as before, only the crop position is changed.

    We can write a function similar to the ProcessLine function from post #98 to handle the right edge:
    Code:
    function ProcessLineRt(clip c, int n){
      crop = c.Crop(684,n*2,36,2) # 36 x 2 px at right
      newcrop = ScriptClip(crop, "
        white = int(AverageLuma(Crop(0,0,6,2))) #get the average luma of the left pixels
        black = int(AverageLuma(Crop(30,0,6,2))) #get the average luma of the right pixels
        margin = (white - black)/3
        Levels(black + margin, 2, white - margin/2, 0, 255, coring=false) #adjust the level to make the left real white and right real black
      ")
    
       return (n < 239) ?  StackVertical(newcrop, ProcessLineRt(c, n + 1)) : newcrop
    }
    Then the left and right processing can be performed together with:

    StackHorizontal(ProcessLine(0), Crop(36, 0, -36, 0), ProcessLineRt(0))
    Quote Quote  
  18. oh yes.. sorry. It was so obvious.
    Thank you
    Quote Quote  
  19. delete
    Image Attached Images  
    Last edited by Cherbette; 2nd Nov 2011 at 15:47. Reason: started own thread
    Quote Quote  



Similar Threads

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