New colormatching script :: 1 > 3

  • Reply
  • Print
g-force's avatar
New colormatching script

Here is an avisynth script that I worked up that TRIES to match the colors of one source with another. Your mileage may vary. Feel free to comment, leave feedback, suggestions, examples etc. here.

 

 

Function RGBMatch(clip gref, clip bref, clip "input", int "mix")

{# v1.2 - by G-force

 # Make Red, Green and Blue channel average, (and min and max) of second clip match first clip

 # or optionally, make third clip match difference between first two

 # i.e., if the cropping is different between the sources, you could crop the sources first

 # to better match each other and then only apply the result to the third (uncropped) clip

 # mix = how much min/max compensation to do, 0=none (average only), 255=fully match min/max (default)


input  = Default(input,bref)

mix    = Default(mix,255)          


global gref = gref

global bref = bref

global input = input

global mix = mix


scriptclip(bref,"""


grefrgb=gref.ConvertToRGB()

brefrgb=bref.ConvertToRGB()

inputrgb=input.ConvertToRGB()


grefr = grefrgb.ShowRed().ConvertToYV12()

grefg = grefrgb.ShowGreen().ConvertToYV12()

grefb = grefrgb.ShowBlue().ConvertToYV12()

brefr = brefrgb.ShowRed().ConvertToYV12()

brefg = brefrgb.ShowGreen().ConvertToYV12()

brefb = brefrgb.ShowBlue().ConvertToYV12()

inr = inputrgb.ShowRed().ConvertToYV12()

ing = inputrgb.ShowGreen().ConvertToYV12()

inb = inputrgb.ShowBlue().ConvertToYV12()


y1r = AverageLuma(grefr)

y1g = AverageLuma(grefg)

y1b = AverageLuma(grefb)


y2r = ((255-mix)*0+mix*Yplanemin(grefr))/255

y2g = ((255-mix)*0+mix*Yplanemin(grefg))/255

y2b = ((255-mix)*0+mix*Yplanemin(grefb))/255


y3r = ((255-mix)*255+mix*Yplanemax(grefr))/255

y3g = ((255-mix)*255+mix*Yplanemax(grefg))/255

y3b = ((255-mix)*255+mix*Yplanemax(grefb))/255


x1r = AverageLuma(brefr)

x1g = AverageLuma(brefg)

x1b = AverageLuma(brefb)


x2r = ((255-mix)*0+mix*Yplanemin(brefr))/255

x2g = ((255-mix)*0+mix*Yplanemin(brefg))/255

x2b = ((255-mix)*0+mix*Yplanemin(brefb))/255


x3r = ((255-mix)*255+mix*Yplanemax(brefr))/255

x3g = ((255-mix)*255+mix*Yplanemax(brefg))/255

x3b = ((255-mix)*255+mix*Yplanemax(brefb))/255


#compute coefficients for y=ax^2+bx+c using min, avg, max


ar  = x1r==x2r? 0: x1r==x3r? 0: x2r==x3r? 0:

 \ (y3r-y1r+(x1r-x3r)*(y1r-y2r)/(x1r-x2r))/((x1r-x3r)*(x2r-x3r))

br  = x1r==x2r? 0:

 \ ((y2r-y1r)/(x2r-x1r))-ar*(x1r+x2r)

cr  = y1r-ar*x1r*x1r-br*x1r


ag  = x1g==x2g? 0: x1g==x3g? 0: x2g==x3g? 0:

 \ (y3g-y1g+(x1g-x3g)*(y1g-y2g)/(x1g-x2g))/((x1g-x3g)*(x2g-x3g))

bg  = x1g==x2g? 0:

 \ ((y2g-y1g)/(x2g-x1g))-ag*(x1g+x2g)

cg  = y1g-ag*x1g*x1g-bg*x1g


ab  = x1b==x2b? 0: x1b==x3b? 0: x2b==x3b? 0:

 \ (y3b-y1b+(x1b-x3b)*(y1b-y2b)/(x1b-x2b))/((x1b-x3b)*(x2b-x3b))

bb  = x1b==x2b? 0:

 \ ((y2b-y1b)/(x2b-x1b))-ab*(x1b+x2b)

cb  = y1b-ab*x1b*x1b-bb*x1b


inr=inr.MT_lut("x x * "+string(ar)+" * x "+string(br)+" * + "+string(cr)+" +").ConvertToRGB()

ing=ing.MT_lut("x x * "+string(ag)+" * x "+string(bg)+" * + "+string(cg)+" +").ConvertToRGB()

inb=inb.MT_lut("x x * "+string(ab)+" * x "+string(bb)+" * + "+string(cb)+" +").ConvertToRGB()


MergeRGB(inr,ing,inb)


ConvertToYV12()


""")


Return(last)}

 

 

Last edited on December 25, 2012 at 10:47 PM by g-force
You_Too's avatar
RE: New colormatching script

Ok, my first feedback on this updated script is:

After trying it on the 97 SE TB version and 2004 SE DVD of ANH, this time it does indeed lock black and white level it seems, but the saturation comes out way too strong at times.

Could it be that the difference in gamma between the two versions is confusing this script? Or is it that the resulting chroma of this script is matched to a luma difference which is now ignored since the black/white levels are locked?

I'm going to try it on some sources that match a bit better in luma.

Last edited on December 16, 2012 at 5:55 PM by You_Too
g-force's avatar
RE: New colormatching script

Interesting You_Too. Can you post examples of the inputs and output when the saturation is too strong?

-G

You_Too's avatar
RE: New colormatching script

Here's a good example, though when looking at it like this I think it might've been my mistake after all. I had to re-encode the 04 SE that I got from DJ to mpeg2 and it made it darker for some reason. Maybe that's what makes this harder for the script to match it.

97 SE on top, 04 SE in middle and result on bottom.

snicker's avatar
RE: New colormatching script

Gamma difference isn't the issue, You_Too. The 2004 SE (B reference) frame is massively clipped which is causing problems when redistributing the 97 SE RGB luma.

I've equalised the RGB luma in your A & B reference frames to illustrate the extent of the clipping in the 2004 SE. The only way this script might work with the 2004 SE/Blu-ray is if it's modified to affect hue only.

 

snicker's avatar
RE: New colormatching script

 

You_Too, I've modified the Blu-ray to remove most of the clipping from that frame. Would you mind running g-force's script on the following image? Should be a much better result. I've also included an untouched Blu-ray frame (bottom) if you feel like doing a comparison.

 

edit: added untouched (clipped) Blu-ray frame for comparison.

Last edited on December 16, 2012 at 9:38 PM by snicker
You_Too's avatar
RE: New colormatching script

snicker said:

You_Too, I've modified the Blu-ray to remove most of the clipping from that frame. Would you mind running g-force's script on the following image? Should be a much better result.

Yeah, I know the 04 SE is clipped a lot, and got clipped even more when converted back to mpeg2 it seems. I've had better results with some other experiments but I won't post anything just yet.

Anyway, here's that frame of yours run through the script:

Much better! Though if there was a way to make this script also change hues that would be awesome. In the 97 SE Greedo's face and jacket is incorrectly tinted blue, yet they still appear green/teal here after applying the script.

g-force's avatar
RE: New colormatching script

Thanks for helping out snicker! So, You_Too, you might have better results with the average only (as opposed to the average/min/max) script I posted yesterday, and then doing a MergeLuma so the results don't affect the brightness at all.

I don't think this approach is going to get you a Blue Greedo however, as this is pretty much just a first-order approximation.

I'll wait to hear back on your results from experimenting before updating the script.

-G

snicker's avatar
RE: New colormatching script

Hue maps (top to bottom) - Blu (source), 97 SE (reference), color match result (g-force's script):

 

Last edited on December 17, 2012 at 12:44 AM by snicker
snicker's avatar
RE: New colormatching script

Blu-ray matched using 'Match Color' in Photoshop: Photoshop result (top) and hue map (middle), 97 SE hue map (bottom).

You_Too, this seems to be a fairly accurate translation of your reference colours.

 

Last edited on December 16, 2012 at 10:56 PM by snicker
You_Too's avatar
RE: New colormatching script

snicker said:

You_Too, this seems to be a fairly accurate translation of your reference colours.

I don't know, it looks quite off. The wall light is yellow for example.

Anyway, let's not get stuck in this bad example, using that mpeg2 encode I made just for frame matching. I think g-force's new script can be useful for other things. I'm looking into some possibilities.

timdiggerm's avatar
RE: New colormatching script

You_Too said:

Much better!

Indeed, it now resembles a shot from Star Trek (the original series). Which is, really, closer.

snicker's avatar
RE: New colormatching script

You_Too said:

snicker said:

You_Too, this seems to be a fairly accurate translation of your reference colours.

I don't know, it looks quite off. The wall light is yellow for example.

Reds in both sources have lost subtle highlight detail due to clipping. I've found that once the Blu-ray colour clipping is dealt with, these yellow/orange highlight details show up quite often. They're exaggerated here but not inaccurate.

The hue translation through Photoshop's colour matching is pretty much spot on. If used as a hue adjustment layer for the output from g-force's script (which exhibits less clipping) it should produce quite good results, especially considering the limitations of both sources.

Last edited on December 17, 2012 at 7:31 AM by snicker
snicker's avatar
RE: New colormatching script

It will be interesting to watch the development of g-force's script. I think we could be on to a winner here.

Moth3r's avatar
RE: New colormatching script

Is this script designed specifically for Star Wars or does it have a more general application?

In other words, would you like this thread moving to the Technical Discussion forum?

Guidelines for post content and general behaviour: read announcement here

Max. allowable image sizes in signatures: reminder here 

g-force's avatar
RE: New colormatching script

Hey Moth3r,

I wondered that as well, but I vote that it stays here for the following reasons:

1. It is stemming from a result of SW restoration specific challenges

2. I'm lazy, and don't visit the other thread often

3. We've had less relavent or simular threads here

Ultimately, your call. Of course we could always move it if and when it starts to be used for other purposes.

-G

AntcuFaalb's avatar
RE: New colormatching script

I did some testing earlier tonight.

This script successfully matches the colors in GOUT to those in the '85 CAV P&S LD!

"And I'm shocked at you Moth3r for being off-topic, Because if people off-topic you say "stay on-topic, STAY on-topic, STAY ON-TOPIC", and we are not in the Off topic section of OT.com, now are we?" –pat man

"Look again." –Moth3r

bkev's avatar
RE: New colormatching script

Can we see some before/after shots?

AntcuFaalb's avatar
RE: New colormatching script

bkev said:

Can we see some before/after shots?

Sure. They're not perfect and do note that I didn't do any levels-correction.

Sample 1

Sample 2

Sample 3

Sample 4

Sample 5

Sample 6

"And I'm shocked at you Moth3r for being off-topic, Because if people off-topic you say "stay on-topic, STAY on-topic, STAY ON-TOPIC", and we are not in the Off topic section of OT.com, now are we?" –pat man

"Look again." –Moth3r

Mavimao's avatar
RE: New colormatching script

Wow, that's pretty impressive! But man some of those shots are a tad too bright.

What's the internal temperature of a TaunTaun? Luke warm.

frank678's avatar
RE: New colormatching script
Wow, so you recoloured a widescreen version using a pan and scan version (?)! Can this script work from single stills?
AntcuFaalb's avatar
RE: New colormatching script

Mavimao said:

Wow, that's pretty impressive! But man some of those shots are a tad too bright.

Mavimao: I agree, but keep in mind that I didn't correct the levels in either source. The end result would be darker if I had.

Everyone: For the record, this was only an experiment.

"And I'm shocked at you Moth3r for being off-topic, Because if people off-topic you say "stay on-topic, STAY on-topic, STAY ON-TOPIC", and we are not in the Off topic section of OT.com, now are we?" –pat man

"Look again." –Moth3r

AntcuFaalb's avatar
RE: New colormatching script

frank678 said:

Wow, so you recoloured a widescreen version using a pan and scan version (?)! Can this script work from single stills?

It works frame-by-frame for all of IP reel #1, at least. Interestingly, it doesn't display the characteristic flicker one would expect.

I IVTC'd the Pan&Scan version, isolated IP reel #1, and then temporally-aligned that to IP reel #1 from GOUT resulting in, of course, all matching frames.

I then applied g-force's RGBMatch to each clip and took some samples.

"And I'm shocked at you Moth3r for being off-topic, Because if people off-topic you say "stay on-topic, STAY on-topic, STAY ON-TOPIC", and we are not in the Off topic section of OT.com, now are we?" –pat man

"Look again." –Moth3r

AntcuFaalb's avatar
RE: New colormatching script

frank678 said:

Wow, so you recoloured a widescreen version using a pan and scan version (?)! Can this script work from single stills?

1. Yes

2. I haven't tried yet, but I'm pretty sure it can.

"And I'm shocked at you Moth3r for being off-topic, Because if people off-topic you say "stay on-topic, STAY on-topic, STAY ON-TOPIC", and we are not in the Off topic section of OT.com, now are we?" –pat man

"Look again." –Moth3r

pittrek's avatar
RE: New colormatching script

AntcuFaalb said:

bkev said:

Can we see some before/after shots?

Sure. They're not perfect and do note that I didn't do any levels-correction.

Sample 1

Sample 2

Sample 3

Sample 4

Sample 5

Sample 6

Would you do the whole movie ? I like the colours

Members reading this topic: None