VideoHelp Forum




+ Reply to Thread
Results 1 to 12 of 12
  1. Hi, I'm wondering whether there's a filter for avisynth which detects only grayscale colours in an image and removes all the rest of colours in it.

    For example, I have some images with black and green colours. I want to detect only the black or gray colours, and remove the green.
    I can do that in photoshop, but I have a large amount of images that need to be processed like that.

    I've read that Layer Filter can do that, but I can't find it anywhere.

    Any help would be appreciated. It doesn't matter if it's not an avisynth filter but another software.

    Thanks in advance.
    Quote Quote  
  2. I find the description of what you want to do confusing. You want to keep the greyscale parts of the image and do what with the colored parts? Make them greyscale? Make them black? Some other color? You only need to process the green? Or all colors?
    Quote Quote  
  3. Originally Posted by jagabo View Post
    I find the description of what you want to do confusing. You want to keep the greyscale parts of the image and do what with the colored parts? Make them greyscale? Make them black? Some other color? You only need to process the green? Or all colors?
    Hi, jagabo. Thanks for your reply.
    I need to "remove" the coloured parts. I mean, make them white.
    Quote Quote  
  4. There are probably easier ways but here's one that uses only basic tools built into AviSynth:

    Code:
    function AbsChroma(clip src)
    {
      # sum of abs(chroma-128)
    
      posu=UtoY(src).ColorYUV(off_y=-128)
      negu=Invert(src).UtoY().ColorYUV(off_y=-128)
    
      posv=VtoY(src).ColorYUV(off_y=-128)
      negv=Invert(src).VtoY().ColorYUV(off_y=-128)
    
      Overlay(Overlay(posu,negu,mode="Add"), Overlay(posv,negv,mode="Add"),mode="Add").BicubicResize(src.width, src.height)
    }
    
    src=AviSource("source.avi") # get source file
    white=ColorYUV(src, off_y=256, cont_u=-256, cont_v=-256) # make a white video
    mask=AbsChroma(src).ColorYUV(off_y=-4).ColorYUV(gain_y=256000) # convert chroma to a mask
    
    Overlay(src,white,0,0,mask)
    In the mask=AbsChroma() line off_y is a threshold (how perfectly grey a pixel has to be to be replaced), change gain_y if you want less sharp edges. Also play around with gamma_y instead of or in addition to gain_y.
    Last edited by jagabo; 16th Mar 2013 at 12:07.
    Quote Quote  
  5. Member AlanHK's Avatar
    Join Date
    Apr 2006
    Location
    Hong Kong
    Search Comp PM
    Maybe this:
    http://forum.doom9.org/showthread.php?t=151259

    But I'm not sure about "Black". Video uses RGB and a few other spaces I have less familiarity with, but I don't think it uses CMYK.
    Quote Quote  
  6. Originally Posted by jagabo View Post
    There are probably easier ways but here's one that uses only basic tools built into AviSynth:

    Code:
    function AbsChroma(clip src)
    {
      # sum of abs(chroma-128)
    
      posu=UtoY(src).ColorYUV(off_y=-128)
      negu=Invert(src).UtoY().ColorYUV(off_y=-128)
    
      posv=VtoY(src).ColorYUV(off_y=-128)
      negv=Invert(src).VtoY().ColorYUV(off_y=-128)
    
      Overlay(Overlay(posu,negu,mode="Add"), Overlay(posv,negv,mode="Add"),mode="Add").BicubicResize(src.width, src.height)
    }
    
    
    src=AviSource("source.avi") # get source file
    white=ColorYUV(src, off_y=256, cont_u=-256, cont_v=-256) # make a white video
    mask=AbsChroma(src).ColorYUV(off_y=-4).ColorYUV(gain_y=256000) # convert chroma to a mask
    
    Overlay(src,white,0,0,mask)
    In the mask=AbsChroma() line off_y is a threshold (how perfectly grey a pixel has to be to be replaced), change gain_y if you want less sharp edges. Also play around with gamma_y instead of or in addition to gain_y.
    That code really works!
    Thanks a lot.

    However, I can't figure out how to load images instead of videos in "src".
    When loading an image, I get the following error:

    "ColorYUV: requires YUV input"
    Quote Quote  
  7. Originally Posted by AlanHK View Post
    Maybe this:
    http://forum.doom9.org/showthread.php?t=151259

    But I'm not sure about "Black". Video uses RGB and a few other spaces I have less familiarity with, but I don't think it uses CMYK.
    Hi, AlanHK.
    Thanks for your reply.

    I'll take a look at that filter.
    Quote Quote  
  8. Member AlanHK's Avatar
    Join Date
    Apr 2006
    Location
    Hong Kong
    Search Comp PM
    Originally Posted by Guado View Post
    However, I can't figure out how to load images instead of videos in "src".
    When loading an image, I get the following error:

    "ColorYUV: requires YUV input"
    Code:
    src=ImageSource("image.png").ConvertToYV24(()
    see
    http://avisynth.org/mediawiki/ImageSource
    http://avisynth.org/mediawiki/Convert
    Quote Quote  
  9. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    For a less exact shorter version of what jagabo sugggested, you could always just use Greyscale().

    Scott
    Quote Quote  
  10. Originally Posted by Cornucopia View Post
    For a less exact shorter version of what jagabo sugggested, you could always just use Greyscale().
    No, the code I posted converts all colored pixels bright white. So, for example, a dark red pixel becomes white, not dark grey.
    Quote Quote  
  11. Thanks, the code is working now.
    Quote Quote  
  12. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    ...I see where that came from now. Guess I never fully understood the nature of the question. Still don't. What would this be used for?

    Scott
    Quote Quote  



Similar Threads

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