View Full Version : Unusual colour correction
valja
13th January 2009, 18:29
I'm trying to fix a rip from very old tape. The picture is hevily filled by red. Somehow helps VirtualDub RGB filter "color equalizer" - shifting red by -90 almost normalizes picture, but not entirely. In this case upper side of screen has lack of red, bud lower side has still too much red. Pictures are swapped, original picture is right:
http://valja.offline.ee/TA/TA1.jpg
Is there any way to shift red (in RGB), smoothly changeing red shift, say, from -66 in upper side of frame to -114 in lower side of frame (-66 for the upper 10 lines, -67 for the next 10 lines and so on)?
valja
14th January 2009, 19:19
Finally I found solution. Screen height is 384, so I divided it to 48 parts by 8 pixels from up to down, then made colour correction for every part separately and finally joined corrected parts back together.
ConvertToRGB24()
s0=last
function partN(clip "s0", int "no")
{
n1 = (no-1)*8
n2 = n1-376
red = -(66 + no)
redgain = (no-24)/100 + 1.207
out = crop(s0,0,n1,0,n2)
out = RGBAdjust(out,r=redgain,g=1.07,rb=red)
return out
}
s1=partN(s0,1)
s2=partN(s0,2)
s3=partN(s0,3)
..............
s48=partN(s0,48)
final=StackVertical(s1,s2,s3,......,s48)
return final
Well, this code looks a bit ugly and for sure can be written in a more elegant and universal way. But it does the job I need. :)
thetoof
14th January 2009, 20:45
There should be a quicker and more "elegant" way of doing it via masktools2... I can't look into it right now, but I'm throwing the ball to anyone who'd want to catch it :p
Meanwhile, you could check how deblock_qed for mt2 uses mt_lutspa for some inspiration.
Sagekilla
15th January 2009, 01:35
A good way would be to create a grayscale mask that varies from dark gray to pure white from top to bottom. Then, apply color correction to the video and mask it out using the bitmap image.
Something like this (in pseudo code, don't try this actual script!):
a = source
b = a.rgbadjust()
c = imagereader("mask.bmp")
mt_merge(a,b,c)
valja
15th January 2009, 16:32
a = source
b = a.rgbadjust()
c = imagereader("mask.bmp")
mt_merge(a,b,c)
Thanx! Hopefully I got the point. As I understand, first I have to apply maximum correction (clip b), and then mask it out.
In fact it will be a bit more complicated, because there are actually three color corrections: red shift from -66 to -104, red gain change from 0.977 to 1.447, and static green gain 1.07. So I have to do them step by step.
Everything is OK with first correction. All corrected pixels are between original (rb=0) and maximum (rb=-114), mask for it has to have upper pixels set to 150 (=255*67/114) and lower to 255.
But there is slight problem with second one. Red gain is corrected in two directions - down to 0.977 in upper side and up to 1.477 in lower side. By blending original (rg=1.0) and maximum (rg=1.477) I can not get the value 0.977. So I have to create additional clip with rg=0.977 of original value and then use mt_merge() with mask from 0 to 255.
And ststic green correction can be done without masking. So, finally it probably should look something like
a = source
b = a.rgbadjust(max_red_shift, max_red_gain)
c = imagereader("mask.bmp")
d = mt_merge(a,b,c)
e = d.rgbadjust(red_gain = 0.661)
f = imagereader("mask2.bmp")
mt_merge(d,e,f)
rgbadjust(static_green_correction g=1.07)
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.