Log in

View Full Version : Saturated colors bleed - no more


ajordan
29th May 2004, 22:18
Hi! I've been working on a filter to fix a severe color bleeding problem of my low-end camcorder (JVC DVL510). I managed to fix it with this function, which works in YV12 colorspace. I hope this is usefull to somebody else.

Function FixChromaBleeding (clip input) {

# prepare to work on the V channel and reduce to speed up and filter noise
area = input.tweak(sat=4.0).VtoY.ReduceBy2

# select and normalize both extremes of the scale
red = area.Levels(255,1.0,255,255,0)
blue = area.Levels(0,1.0,0,0,255)

# merge both masks
mask = MergeLuma(red, blue, 0.5).Levels(250,1.0,250,255,0)

# expand to cover beyond the bleeding areas and shift to compensate the resizing
mask = mask.ConvertToRGB32.GeneralConvolution(0,"0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0").ConvertToYV12

# back to full size and binarize (also a trick to expand)
mask = mask.BilinearResize(Width(input),Height(input)).Levels(10,1.0,10,0,255)

# prepare a version of the image that has its chroma shifted and less saturated
input_c = input.ChromaShift(C=-4).tweak(sat=0.8)

# combine both images using the mask
return input.overlay(input_c,mask=mask,mode="blend",opacity=1)
}

More details and sample images here (http://www.geocities.com/alex_j_jordan/index.htm)... The pic below is an appetizer ;)

http://img8.imageshack.us/img8/708/chroma.jpg

Mug Funky
31st May 2004, 07:16
that's pretty good thinking there.

would a soft mask help it? (or would it just slow it down some...). i'm pretty big on soft masks, but they're not always useful.

t610425
31st May 2004, 07:31
Color bleeding is a pain for me, specialy when transfering old (PAL) VHS to DVD.

I'll give it a try and let you know.

tnx for sharing

all the best

ajordan
31st May 2004, 14:58
@Mug: You mean to use gamma > 1.0 in Level? I don't think it would slow down at all. If I can make sure the bleeding area is well covered by the soft mask, it would reduce the risk of yanking the croma of a nearby object into the correction. Thanks for the suggestion.

Boulder
8th November 2005, 16:38
Could any MaskTools guru make a faster version of this excellent function? It seems that the discussion dried up short ;)

trevlac
8th November 2005, 17:48
At the risk of introducing a different but probably not better way .... :D

I added some functionality to Tweak a little while ago to allow targeting specific hues and saturation levels (secondary color correction). So you can target a range of red hue and a range of saturation and then bring those pixels down. It does allow a 'softening' of the saturation window by interpolating over a range instead of a sharp cutoff. This helps to reduce banding.

http://www.avisynth.org/warpenterprises/files/tweakcolor_25_dll_20040412.zip


[edit]
#This should Target red between 115% and 75% saturation
# and bring it down to 80% of the original value.
# Smoothing defaults to 16 which will dampen saturations down to (75-16=59%)

TweakColor(sat=0.8,startHue=80,endHue=140,maxSat=115,minSat=75)

Didée
9th November 2005, 09:46
Could any MaskTools guru make a faster version of this excellent function? It seems that the discussion dried up short ;)
That script could be optimised quite heavily. But beyond optimisation, a complete re-write would be much better. The script currently uses a "fixed" offset, which basically is a hack: there could be *completely other* offsets out there as well, on which the current function would just fail, in case. Also, currently there's no re-shaping of colors. But if the color bleed is a true "bleed", then re-shaping is needed as well.

For the moment, you should get a good speed gain by just replacing the slow GeneralConvolution # expand to cover beyond the bleeding areas and shift to compensate the resizing
mask = mask.ConvertToRGB32.GeneralConvolution(0,"0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0").ConvertToYV12 with (using MaskTools v1.5.x) mask = mask.DEdgeMask(0,255,0,255,"0 0 0 1 0 0 0 0 0").DEdgeMask(0,255,0,255,"1 1 1 1 1 1 0 0 0")
More speed could be squeezed, but this probably is the most cruicial part.

To produce something that's working more specific, I'd need some samples showing the problem, since I have no such ones.

Boulder
9th November 2005, 10:25
I could try to dig up some frames that have lots of bleeding, it's mostly red and blue which show the phenomenon. I'll probably transfer my last VHS camcorder tape to DVD later this week before getting my first miniDV so I might find something of interest there.

In any case, removing the need to convert to RGB32 and back is already a major point, thanks for that :) I wish I had the time to start learning the basics of masks but it looks like I won't till I'm old and cranky ;)

Chainmax
16th January 2006, 14:33
This script works pretty nicely as it is, so I don't think a rewrite is necessary, but a full optimization would be great if it means the new version would do the exact same thing as the original.

zlab
27th February 2006, 00:45
Hi,
I have difficulty when running the above script "FixChromaBleeding", it report an error: Scipt error: there is no function named "ChromaShift", could anyone give me a hand?

Chainmax
27th February 2006, 02:08
ChromaShift v2.7 (http://www.geocities.com/siwalters_uk/chromashift.html).

FredThompson
1st March 2006, 23:48
Did you try Reinterpolte411? Perhaps that will reduce the initial "bleed" which is really an aspect of 4:1:1, not actual "bleed".

Dr.D
18th September 2006, 03:40
That script could be optimised quite heavily. But beyond optimisation, a complete re-write would be much better. The script currently uses a "fixed" offset, which basically is a hack: there could be *completely other* offsets out there as well, on which the current function would just fail, in case. Also, currently there's no re-shaping of colors. But if the color bleed is a true "bleed", then re-shaping is needed as well.
Is there any progress since a long time ago?
Color bleeding is a real problem for my Sony MiniDV camera. Original script doesn't help, even makes things worse. Because I have bleeding shifted to the left, author has one shifted to the right.
Optimisation of the script will be really appreciated. Thanks!

Pookie
18th September 2006, 09:04
I've found the following to be very effective:

fft3dfilter(sigma=8,plane=3,degrid=1)

Plane=3 affects only the chroma channels, so you can really turn up the sigma levels (within reason).
Try it and see if it helps. Also, the Reinterpolate411 plugin as Fred mentioned might help a lot
if it applies to your source.

Dr.D
18th September 2006, 19:01
I've found the following to be very effective:

fft3dfilter(sigma=8,plane=3,degrid=1)

Plane=3 affects only the chroma channels, so you can really turn up the sigma levels (within reason).
Try it and see if it helps. Also, the Reinterpolate411 plugin as Fred mentioned might help a lot
if it applies to your source.
Thank you, but strange, both ways don't help at all, make no visible difference:
Original:
http://img206.imageshack.us/img206/7589/origvh6.jpg (http://imageshack.us)

Processed:
http://img204.imageshack.us/img204/8577/pookietc6.jpg (http://imageshack.us)

Wilbert
18th September 2006, 22:11
@Dr.D
I tried to make your pics visible, but i didn't get it to work. I will ask the admin about it.

Dr.D
18th September 2006, 22:48
@Dr.D
I tried to make your pics visible, but i didn't get it to work. I will ask the admin about it.
Can you see the pics now?

anton_foy
19th September 2006, 01:03
Isn't there a way to shift colour the planes with TomsmoComp?
Someone suggested me to do that when I had the same problem a long time ago. Can't find the thread though.
Im almost certain it was TomsMoComp :S

Dr.D
19th September 2006, 02:29
Isn't there a way to shift colour the planes with TomsmoComp?
Someone suggested me to do that when I had the same problem a long time ago. Can't find the thread though.
Im almost certain it was TomsMoComp :S
Sounds strange, TomsMoComp is deinterlacing filter, my source is progressive already. Just in case, I've checked out - no difference. Thanks anyway.

real.finder
17th March 2014, 12:49
I have a mod that can control result to fit source

here (https://github.com/realfinder/AVS-Stuff/raw/master/avs%202.5%20and%20up/FixChromaBleedingMod.avsi) (now need Zs_RF_Shared.avsi V1.143 or better)

it good idea to use it like this


FixChromaBleedingMod(-4, 2, thr=4.0, f=false, xysh=true, bic=true, strength=1.0, opacity=1.0) #Shift only
FixChromaBleedingMod(0, thr=3.0, f=false, n=true, strength=0.9, opacity=0.9) #less saturated in blue and red


and there some thing else for chroma blend/bleed/halo here (http://pastebin.com/c9k29ALZ) and here (http://forum.doom9.org/showthread.php?p=1674974#post1674974) related post

romangal
1st September 2021, 22:32
I have a mod that can control result to fit source

here (https://github.com/realfinder/AVS-Stuff/raw/master/avs%202.5%20and%20up/FixChromaBleedingMod.avsi) (now need Zs_RF_Shared.avsi V1.143 or better)

it good idea to use it like this


FixChromaBleedingMod(-4, 2, thr=4.0, f=false, xysh=true, bic=true, strength=1.0, opacity=1.0) #Shift only
FixChromaBleedingMod(0, thr=3.0, f=false, n=true, strength=0.9, opacity=0.9) #less saturated in blue and red


and there some thing else for chroma blend/bleed/halo here (http://pastebin.com/c9k29ALZ) and here (http://forum.doom9.org/showthread.php?p=1674974#post1674974) related post

This script doesnt work correctly. The message appears: There is no function named "Ylevels". But v1.35 works ok. Also i dont know exactly which color formats it is supported? Only YUY2 YV12? And there is no support for YV16 as i see?

kedautinh12
2nd September 2021, 01:07
Ylevels here:
https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/YLevels_mt.avsi

Last ver Zs_RF_Shared.avsi
https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/Zs_RF_Shared.avsi

Last ver FixChromaBleedingMod v1.381
https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/FixChromaBleedingMod.avsi

romangal
2nd September 2021, 01:14
Ylevels here:
https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/YLevels_mt.avsi

Last ver Zs_RF_Shared.avsi
https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/Zs_RF_Shared.avsi

Last ver FixChromaBleedingMod v1.381
https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/FixChromaBleedingMod.avsi
Thank You! Will try it soon. :cool:

kedautinh12
2nd September 2021, 02:20
Since FixChromaBleedingMod v1.38 need Utils-r41.avsi
https://github.com/raffriff42/AvisynthPlusUtilities/blob/master/Utils-r41.avsi