Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 26th May 2012, 12:58   #1  |  Link
dragon_warrior
Registered User
 
Join Date: May 2010
Posts: 123
Matching colors of two clips

The title says it all, I've been trying to match the colors of two clips to remove the logo on one of them. ColourLike seems to be a good treat in this case but the color is a bit exaggerated; as for HistogramAdjust, it crashes everytime I call it. I'm searching for something better to adjust the color of the two clips. Here are what I've done so far:
S1: Youtube
S2: HDTV
E: Test clip (no color-adjusting filters applied)


Thanks and looking forward to your feedback
dragon_warrior is offline   Reply With Quote
Old 26th May 2012, 15:23   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,051
Hi, can you show the script using HistogramAdjust, not sure but I think I may have spotted
a bug for YUY2, did you use YUY2?

EDIT: Think false alarm on the suspected bug, however I would still like to see if I can find the
problem. V.C Mohan wrote this in cpp source

Code:
hbuf= new double[257];	// why 257? Otherwise it gets access violation for vdub closing file error. Could not locate this
So there is definitely a problem somewhere. Give script revealing problem please.
EDIT: You can PM me the script if you dont want to confuse readers on what was done in thread samples.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 26th May 2012 at 16:23.
StainlessS is offline   Reply With Quote
Old 26th May 2012, 15:46   #3  |  Link
Mounir
Registered User
 
Join Date: Nov 2006
Posts: 714
had you searched more you would have found the right filter for that:
http://forum.doom9.org/showthread.php?t=96308
Mounir is offline   Reply With Quote
Old 26th May 2012, 15:54   #4  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
Quote:
Originally Posted by Mounir View Post
had you searched more you would have found the right filter
And if you had read more closely, you would have seen that he already tried that one.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 26th May 2012, 17:03   #5  |  Link
dragon_warrior
Registered User
 
Join Date: May 2010
Posts: 123
Quote:
Originally Posted by StainlessS View Post
Hi, can you show the script using HistogramAdjust, not sure but I think I may have spotted
a bug for YUY2, did you use YUY2?

EDIT: Think false alarm on the suspected bug, however I would still like to see if I can find the
problem. V.C Mohan wrote this in cpp source

Code:
hbuf= new double[257];	// why 257? Otherwise it gets access violation for vdub closing file error. Could not locate this
So there is definitely a problem somewhere. Give script revealing problem please.
EDIT: You can PM me the script if you dont want to confuse readers on what was done in thread samples.
Here it is
Quote:
FFVideoSource("E:\Script\Lady Gaga - Judas 720p HDTV DD5.1 H.264.mkv",fpsnum=50,fpsden=1)
selecteven
tdecimate(cycleR=1,cycle=25)
Spline36Resize(1278,720,0,1,-2,-0)
a=last
mask=ImageSource("E:\Temp\0.png").ConvertToYV12(matrix="PC.601")
logo=FFVideoSource("E:\Script\Lady Gaga - Judas - YouTube.mp4").assumefps(24).Spline36Resize(1278,720,3, 0, -0, -1).trim(1,0).AddGrainC(var=3.5, uvar=0)
logo1=histogram(logo,type="match",mclip=a)
Overlay(a, logo1, mask=mask)
No, I've never processed a yuy2 footage. It's yv12. The filter even crashes on an SD clip, errm, a single frame, to be exact
dragon_warrior is offline   Reply With Quote
Old 26th May 2012, 17:10   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,051
Thankyou, shall have a bit of a play with it.
Found the V.C Mohan noted bug, his fix (using 257 instead of 256) should have kept it hidden. EDIT: Have PM'ed him.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 26th May 2012 at 17:37.
StainlessS is offline   Reply With Quote
Old 26th May 2012, 17:16   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,051
Hi, cant seem to find HistogramAdjust in the script
Perhaps the usage of Histogram() is wrong.

EDIT:
Quote:
it crashes everytime I call it
Looks like Histogram might be complaining about args {Histogram (clip, string ''mode''[, float ''factor'']) }
EDIT: is there a 601-709 color mismatch between HD and mp4 clips for ColorLike script?
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 27th May 2012 at 09:10.
StainlessS is offline   Reply With Quote
Old 27th May 2012, 01:46   #8  |  Link
dragon_warrior
Registered User
 
Join Date: May 2010
Posts: 123
Sorry, it should have been histogramadjust(logo, type="match", mclip=a)
dragon_warrior is offline   Reply With Quote
Old 27th May 2012, 09:16   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,051
@dragon_warrior,
Let us know if it does anything of use.

To all,

Would removing gamma (RGB) on clips before HistogramAdjust/Colorlike and restoring after be beneficial ?
EDIT: HistogramAdjust is YV12-YUY2 and operates on Luma Only.
EDIT: No, forget that, probably rubbish.

EDIT: Thread with a few more ideas on colorLike and similar: (but colorLike looks best for purpose)
http://forum.doom9.org/showthread.php?t=157304

EDIT: Maybe using the UtoY type stuff you could use HistogramAdjust on all three channels.

EDIT: The great VectorScope by Trevlac (pics in ColorLike thread) for VDUB with AVSI for Avisynth
can be found below, (didnt realise that I already had it, called clrtools.vdf)
http://forum.doom9.org/showthread.ph...ht=vectorscope
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 27th May 2012 at 11:06.
StainlessS is offline   Reply With Quote
Old 27th May 2012, 14:18   #10  |  Link
dragon_warrior
Registered User
 
Join Date: May 2010
Posts: 123
Quote:
Originally Posted by StainlessS View Post
@dragon_warrior,
Let us know if it does anything of use.

To all,

Would removing gamma (RGB) on clips before HistogramAdjust/Colorlike and restoring after be beneficial ?
EDIT: HistogramAdjust is YV12-YUY2 and operates on Luma Only.
EDIT: No, forget that, probably rubbish.

EDIT: Thread with a few more ideas on colorLike and similar: (but colorLike looks best for purpose)
http://forum.doom9.org/showthread.php?t=157304

EDIT: Maybe using the UtoY type stuff you could use HistogramAdjust on all three channels.

EDIT: The great VectorScope by Trevlac (pics in ColorLike thread) for VDUB with AVSI for Avisynth
can be found below, (didnt realise that I already had it, called clrtools.vdf)
http://forum.doom9.org/showthread.ph...ht=vectorscope
Thanks for all of your EDITs
Maybe I'll use the last 2 functions in this post http://forum.doom9.org/showthread.ph...07#post1448607, plus merge and applyrange for my final script. Anyway, the red in the copy from Youtube tends to be duller than that of the HDTV capture, and I don't know how to fix it.
As for the plugin you point me to (clrtools.vdf), how can I use it for my purpose?
dragon_warrior is offline   Reply With Quote
Old 27th May 2012, 15:05   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,051
Quote:
As for the plugin you point me to (clrtools.vdf), how can I use it for my purpose?
Thats your problem

But, thought that the plug would be generally interesting for anybody messing with color. Suggest that
you fire up VDMod and load any AVS, (with clrtools.vdf in VDMod plugins) and load the clrtools filter, and
in filter gui select VectorScope mode to view what it looks like and perhaps play with other settings.
Once you feel you know what it does, then see the AVSI source (you would need to comment out
the embedded examples) and you should be able to figure out how to use the plugin in Avisynth to
eg view clip vectorscopes side by side (needs a convert to RGB for VD filter).
Best see the thread on clrtools for interpretation of the vectorscope and other graphs (I think they're very pretty).
Generally, I think the cluster of data in vectorscope should be the same general shape, if rotated it would
I think mean a change in hue, and change in size would mean change in the saturation (If I understand it correctly).
EDIT: Native Avisynth version here:
http://avisynth.org.ru/docs/english/...ers/vscope.htm

For your info, Have got most recent source (25 aug 05) and compiled it and it resulted in exact same size
as the ColourLike_25Aug05.dll I have (208,896 bytes), hope you are using that one. The old one with a bug
in it is ColourLike_230505.dll (139,264 bytes).
EDIT: There is also a ColourLike.dll (270,336 bytes) knocking around built by Neuron2 using 25Aug05 source,
differing in size perhaps because of Avisynth.h version 3 (one I build used orig V2 for identical file size),
Or, perhaps Neuron2 used VS6 or another compiler, I used TK3 for identical build size.
Source and original good version dll using current source, and Neuron2's build available here:
http://forum.doom9.org/showthread.php?t=118430
or original dll only from here:
http://avisynth.org/warpenterprises/

My Bad, did not use VS6 for 208,896 bytes build, was TK3 (oops), VS6 builds with 8 int i redefinition errors.

The documentation of ColourLike is a bit sparse and scattered over the included help file, and multiple posts in the Colourlike
thread, I'm currently trying to put together (in one place) a more full description, shall have to also extract some of that info
from the source as even collecting the scattered docs together leaves some holes.

I include below the rough text I am editing right now, shall modify when done editing, hope it helps if you have more
complete info than in the helpfile.

Code:
ColourLike:  http://forum.doom9.org/showthread.php?t=96308

by mg262,

Search keywords: colour, color, ColorLike, curve, gamma, levels, channel.

Brief description: Makes a clip look like a 'reference' clip by adjusting each colour channel.

Full description:

  YV12 and it now has RGB32 support.

  It also has a polar-YUV mode, which as its 3 channels has
      1) Y,
      2) Length of the UV-vector (saturation)
      3) Angle of the UV-vector. (hue)
    Currently the angle is not changed by the filter (ie does not change hue).

  Be careful to feed the filter with the right kind of histogram... YUV, RGB and Polar-YUV are three different kinds. 


  Functions:

  
    WriteHistogram(clip,string outputfile, int  "every"=1)
      YV12, RGB32
      Computes histograms for each channel of the clip and stores the results in outputFile.
      If e.g.  every=3 is specified, only every 3rd frame of clip is sampled.
      # Returns original clip (No Constructor)


    #CopyHistogram(string InputFilename, string OutputFilename) 
    #  Copy a histogram ie make duplicate file.
    #  Not Implemented (Implememted in source but commented out) 
    
    
    WritePolarHistogram(clip,string outputfile, int  "every"=1)
      YV12 Only, Emits a "Requires RGB32" message if NOT YV12 ???
      Computes polar histograms for each channel of the clip and stores the results in outputFile.
      If e.g.  every=3 is specified, only every 3rd frame of clip is sampled.
      # Returns original clip (No Constructor)
    
        
    CopyPolarHistogram(string InputFilename, string OutputFilename)
      Copy a Polar histogram ie make duplicate file.
      # Returns 0
    
    
    WriteColourLikeCurve(string OutputFilename, string sourceHistogramFile, string referenceHistogramFile)
      Writes YUV Equalising curves
      # Returns 0
    
    
    ColourLike(clip source,string sourceHistogramFile,string referenceHistogramFile, \
              bool "affectfirst"=true, bool "affectsecond"=true,bool "affectthird"=true)
      YV12, RGB32 
      Takes a clip source and histogram files for this clip and a reference clip, and applies curves to each channel
      chosen, to make source look as much like the reference as possible.
    
      
    PolarColourLike(clip source, string sourceHistogramFile,string referenceHistogramFile, \
           bool "affectfirst"=true, bool "affectsecond"=true,bool "affectthird")
      YV12 Only # RGB32, Not implemented for RGB32 depite error msg saying YV12 & RGB32 only
      Takes a clip source and histogram files for this clip and a reference clip, and applies curves to the clip,
      to make source look as much like the reference as possible.
      affectfirst, affects Y channel
      affectsecond, affects length of the UV-vector (ie SATURATION)
      affectthird, if supplied is IGNORED, (angle of the UV-vector) (ie Does not change HUE)   
      The first true tells the filter to affect luma, and the second true tells it to affect saturation.

  
    ApplyAMP(clip, string CurveFilename)
      YV12, RGB32
      Affects Y channel only for YV12


    SaturationGamma(clip, float gamma, float "fixed"=127.0)
      YV12
      Affects U & V channels Only (applies gamma to length of the UV-vector [SAT])
      Y channel untouched
        I've also added a saturation gamma function. The idea is this. A normal gamma operation can brighten or darken
        midtones while (approximately) leaving highlights and shadows alone. The saturation Gamma can increase or decrease
        the saturation of areas with medium saturation, while leaving greys and very saturated areas alone. 
        The fixed parameter gives a "very saturated" saturation level [measured as a distance from (128,128)] that will
        be left alone by the function... but it will work fine if you leave this number at default.
        The results are (in my view) quite interesting, so do give it a go!
        

----------------

Examples:

  Here are some examples from a case where the same clip is present in (unrelated) DVD and VHS sources.

  First generate the histograms:

  dvd.WriteHistogram("dvd hist 100.txt", 100)
  vhs.WriteHistogram("vhs hist 100.txt", 100)

  Then, say, adjust the VHS to look as much like the DVD as possible:
    vhs.colourlike("vhs hist.txt", "dvd hist.txt")
  or 
    vhs.colourlike("vhs hist.txt", "dvd hist.txt", true, false, false)
      which means: just process Y (respectively R) but ignore U and V (respectively G and B).

  Or adjust the DVD to look as much like the VHS as possible
  dvd.colourlike("dvd hist.txt", "vhs hist.txt")

  Polar:
    dvd
    WritePolarHistogram("dvd polar hist 1.txt", 1)
    vhs
    WritePolarHistogram("vhs polar hist 1.txt", 1)
    
    dvd.polarcolourlike("dvd polar hist 1.txt", "vhs polar hist 1.txt", true, true, true) #last 'true' is ignored

      The first true tells the filter to affect luma, and the second true tells it to affect saturation.
      This should in theory change the brightness, contrast, saturation, etc but not affect hue.
      I haven't found this to be very useful in practice.
      I think a variant which changed hue would be more useful, but this is ill-defined... or more precisely, 
      because hue is represented by a circle rather than a line, there is a whole family of 'hue-equalising' filters...

------------------------------------------------------------------------------------------------
Notes:
  Generating histograms runs at about 75fps on DVD source on my PC (and I think most of that time is MPEG decoding), but
  this still seems slow because the entire file needs to be scanned. As in the example, you can specify quite a large
  value of 'every' without affecting the results too much.

  You only need to generate the histograms once, so you probably want the WriteHistogram calls in a separate AVS to
  ColourLike.

  This filter can be used on completely unrelated clips (which I haven't tried yet); I don't actually think that is a
  particularly meaningful thing to do, so I'm pretty pessimistic about the results -- but if you do happen to try it,
  see what the results look like when you just use it on the Y channel, and also when you just use it on the U&V channels.
  (Use MergeLuma or MergeChroma with source and the output of this filter.)

  For the record, I'm not terribly happy with the results of the filter overall -- as I noted in that other thread, I
  think there is 'crosstalk' between the colour channels that this process does not account for. So I think a proper colour
  matching function will have to use something more sophisticated than channel-curves.

The 'other thread' mentioned is here:
http://forum.doom9.org/showthread.php?t=95574

------------------------------------------------------------------------------------------------------------------------
Above text, mostly words of author mg262, but edited from various posts on doom9 and had some text inserted to either
clarify or denote usage.

Edited by StainlessS, on doom9
EDIT: ClipClop could well be more flexible than ApplyRange.

EDIT: Updated ColourLike helpfile
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 1st June 2012 at 03:32.
StainlessS is offline   Reply With Quote
Old 28th May 2012, 02:33   #12  |  Link
dragon_warrior
Registered User
 
Join Date: May 2010
Posts: 123
VectorScope seems pretty good, but I still don't know how to make use of it. Thoughts?
And if I want to use it I must undergo double color conversion?
dragon_warrior is offline   Reply With Quote
Old 28th May 2012, 03:37   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,051
Quote:
Originally Posted by dragon_warrior View Post
VectorScope seems pretty good, but I still don't know how to make use of it. Thoughts?
And if I want to use it I must undergo double color conversion?
Me neither, but it does look pretty, think less useful for brightness, lightness, value, luma, but pretty good for sat
and hue (which are totally more understandable than two measures of U & V chroma).

"undergo two measures of conversion", No not really, just to view, not suggesting that you convert to rgb and then back
for the rendering (You always view in RGB anyway).

Dont know if this will at all help but, I quite a long time ago withdrew ColorYUV2 which I made a
grapher for (Grapher in Mediafire sig, Toys.zip). But got a bit miffed about something and so withdrew that dll, I actually
habitually use the dll and intend to mod it to use the v2.6 avisynth version, think it's
been changed (some day). Anyway, shall do you a non debug version (temp) and hopefully you can view a before and after version of your
YouTube clip against the hires clip, as you mod it (in RGB->YUV->RGB in Grapher, as if it were done in YUV, {arh, now I
remember, had probs with finding non conflicting matrices for eg PC levels and rec.709, so put it on the back burner}
Anyway, either 1 or two days, I'll put up the mod for you and you should mod the YouTube clip to look as close as possible
to the hires one, using the grapher (only works on single RGB bitmaps (convert a frame to RGB rec.601 bmp), needs same frame from
YouTube and Hires) Load the hires frame into one copy of the grapher, without alteration, load low res clip into another
grapher and play with ColorYUV2 settings until match, when happy note settings and then do the Colorlike thing with a ColorYUV2 modified
YouTube clip (as per Grapher noted settings) and original Hirez.

Purpose of above is to get by hand a reasonable approximation to the hires clip, and then let ColourLike split the difference.

Sounds good to me, what say you.

EDIT: Perhaps when using the graphers, might be good to set windows wallpaper to BLACK, (perhaps).

EDIT: On the Graffer, it will also function for ColorYUV official, it just refers to Rpow_y rather than Gamma_y same for chroma,
and has eg SPow_y and for chroma, which is not available in ColorYUV proper. Also Pord_y has no meaning in ColorYUV, it is the
ordering for eg rpow_y and spow_y, ie which is applied first. So you could actually just use it with the standard ColorYUV.
Anyway, the graffer thing allows you to view changes in real time as you alter the sliders and shows a two half screens,
one original and the other the modified half.

Graffer thing here:
http://forum.doom9.org/showthread.php?t=156774

Also a plug to show eg, average luma/chroma of Entire clip as well a frame, could compare both
full clip scans to see mismatch between them.
showChannel:
http://forum.doom9.org/showthread.php?t=163829
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th May 2012 at 18:25.
StainlessS is offline   Reply With Quote
Old 29th May 2012, 08:37   #14  |  Link
Fyx
Registered User
 
Join Date: Apr 2002
Posts: 7
If you aren't already try to exclude the logo from the image when generating the correction. For instance, you could WriteHistogram with the bottom 640 px of both images and hopefully colorlike would give you a more accurate correction.
Fyx is offline   Reply With Quote
Old 29th May 2012, 14:23   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,051
mg262's CompareVersions

Code:
Function CompareVersions(clip A, clip B, bool "copy") {
# (c) mg262, http://forum.doom9.org/showthread.php?p=679687#post679687 
 	A=A.ConvertToYUY2()
 	B=B.ConvertToYUY2()

	copy = default(copy, false)

	halfwidth = A.Width()/2

	left  = A.crop(0, 0, halfwidth,0)
	right = copy ? B.crop(0, 0, halfwidth,0) : B.crop(halfwidth, 0, 0, 0)

	return stackHorizontal(left, right)
}
EDIT: By the way, the vectorscope images on ColourLike thread, I think the upper two images
are the source images (eg dvd and vhs) and the lower two are the two images produced via
ColourLike when converting eg dvd->vhs colors and vhs->dvd colors.
EDIT: There is a native Avisynth version of VectorScope on WarpEnterprises, modded by Wilbert.

EDIT: Updated ColourLike helpfile

EDIT: ColorYUV2() now available here, with Graffers:
http://forum.doom9.org/showthread.php?t=156774
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 1st June 2012 at 03:29.
StainlessS is offline   Reply With Quote
Old 31st May 2012, 10:23   #16  |  Link
dragon_warrior
Registered User
 
Join Date: May 2010
Posts: 123
Thank you very much for the info. I'll check them all when I have finished my exam next Monday
dragon_warrior is offline   Reply With Quote
Old 31st May 2012, 15:25   #17  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 6,051
Good luck with the exams.

Check this out when you've passed your exams:
http://forum.doom9.org/showthread.php?t=165061
Native Avisynth Version Videoscope here:
http://avisynth.org.ru/docs/english/...ers/vscope.htm
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 1st June 2012 at 03:33.
StainlessS is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:38.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.