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 5th April 2011, 22:56   #1  |  Link
Evaldas
Registered User
 
Join Date: Oct 2001
Posts: 52
Looking for filter that increases luma on red only (or blue only) pixels

Hi,

I'm reencoding screencast (screen captured) tutorial videos (slides mixed with unix command line demonstration) from RGB avis to H.264 with x264 encoder. The problem is, that in the outputted video, sequences where unix command line usage is demonstrated, red and blue colors are very washed out and because of that red and especially blue text is hardly readable. I believe this is the problem of x264 encoder, because it can output only in YUV 4:2:0 and thus chroma is subsampled.

So, as a solution I'm thinking to preprocess source videos in avisynth with some filter magic: lighten a bit blue and red colors. Basically I'm looking for filter that examines every pixel and do something like this:

for red pixels
if (Green == 0) and (Blue == 0) and (Red > threshold) then add Luma X

or

if (Hue == 0) then add Luma X

for blue pixels
if (Red == 0) and (Green == 0) and (Blue > threshold) then add Luma X

or

if (Hue == 160) then add Luma X


There's so much to read about avisynth filters and I don't understand everything. If you could just give me a starting point from where to begin studying about particular filter. Is there such a filter? Maybe I'm going the wrong direction, and there are other ways to achieve what I want to do? Thank you

Last edited by Evaldas; 5th April 2011 at 22:59.
Evaldas is offline   Reply With Quote
Old 5th April 2011, 23:07   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,398
Tweak() allows changes to be made selectively based on hue (using the startHue and endHue arguments).

However, chroma subsampling should not cause washed out colours, although it may affect sharpness. Are you sure it isn't a levels/contrast or color matrix problem in your conversion?
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 5th April 2011, 23:13   #3  |  Link
Evaldas
Registered User
 
Join Date: Oct 2001
Posts: 52
Oh, I'm sorry, yes, it's the sharpness of text. Edges of blue and red text are ... I don't know how to say, blurred(?).

Regarding levels/contrast/color matrix, I'm just doing:
Code:
AviSource("Lagarith.avi")
ConvertToYV12()

Last edited by Evaldas; 5th April 2011 at 23:17.
Evaldas is offline   Reply With Quote
Old 6th April 2011, 01:31   #4  |  Link
Evaldas
Registered User
 
Join Date: Oct 2001
Posts: 52
So here's the image with 2 frames. Frame on the left - original picture, frame on the right - converted colorspace. As you see, after conversion, text in red is less readable, text in blue on top is hardly readable. What can be done about this? Is it possible to adjust only red and blue colors?

Evaldas is offline   Reply With Quote
Old 6th April 2011, 09:16   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,398
Why are you using matrix="PC.601"? This will reduce contrast.
Use the default matrix ("Rec601") and you will see an improvement.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 6th April 2011, 23:48   #6  |  Link
Evaldas
Registered User
 
Join Date: Oct 2001
Posts: 52
Using the default matrix, improvement is negligible.

So, with a script I've come to this (blue and red isolated):



Here's the script:
Code:
main = AviSource("source.avi")
red = main.ShowRed()
green = main.ShowGreen()
blue = main.ShowBlue()

onlyBlue = Overlay(Overlay(blue, red, mode="subtract", pc_range=true), green, mode="subtract", pc_range=true)
# onlyBlue = blue - red - green

onlyRed = Overlay(Overlay(red, blue, mode="subtract", pc_range=true), green, mode="subtract", pc_range=true)
# onlyRed = red - blue - green

onlyBlueLeveled = onlyBlue.Levels(85, 1, 150, 0, 255)

onlyRedLeveled = onlyRed.Levels(85, 1, 150, 0, 255)

Overlay(onlyBlueLeveled, onlyRedLeveled, mode="add", pc_range=true)

# RedAndBlue = Overlay(onlyBlueLeveled, onlyRedLeveled, mode="add", pc_range=true)
What's next? How can I use "RedAndBlue" with the source avi to brighten red and blue colors?
Evaldas is offline   Reply With Quote
Old 7th April 2011, 02:48   #7  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 4,191
This doesn't answer your question directly, but maybe you can combine some "small improvements"



ResampleHQ is a gamma aware resizer, but YV12 is currently broken
http://forum.doom9.org/showthread.php?t=160038

This was done with avisynth 2.6 (2.5.8 scales the chroma slightly differently), also note the text labels are missing quotation marks in the screenshot, e.g. it should be

ResampleHQ(dstcolorspace="YUY2")

instead of

ResampleHQ(dstcolorspace=YUY2)

You can try YUY2toYV12_26 , instead of ConvertToYV12() it might be marginally better (I think some letters are better, some are worse)

Using larger resolution and/or font size is also another approach (even upscale with nnedi3)
poisondeathray is offline   Reply With Quote
Old 7th April 2011, 17:43   #8  |  Link
Evaldas
Registered User
 
Join Date: Oct 2001
Posts: 52
poisondeathray, thank you very much, I've could not imagined that someone would do these kinds of test to help others. Thank you.

Well, I've figured out that I could simply overlay black and white picture (red and blue isolated) on top of main picture using "add" mode.

Code:
Overlay(main, RedAndBlue, mode="add", pc_range=true)
Here's the result (ConvertToYV12 already done):


I'm quite satisfied with the result. Thank you everyone for your input helping me.

Full script, if some is interested:
Code:
main = AviSource("source.avi")

bluered = Overlay(Overlay(main.ShowBlue(), main.ShowRed(), mode="add", pc_range=true), main.ShowGreen(), mode="subtract", pc_range=true).Levels(0, 1, 255, 0, 128)

ConditionalFilter(main.ConvertToYV12(), main.ConvertToYV12(), Overlay(main, bluered, mode="add", pc_range=true).ConvertToYV12(), "AverageLuma()", ">", "150")

Last edited by Evaldas; 11th August 2011 at 02:32. Reason: full script added
Evaldas 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 16:35.


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