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 19th October 2014, 00:49   #1  |  Link
Lyris
Registered User
 
Join Date: Sep 2007
Location: Europe
Posts: 601
How to set just-above-black shades to black? (Coring?)

I have a really tough source which needs all the compression help it can get. There's a lot of low-level grain and noise that could do with being simplified prior to compression.

Let's say (taking into account that black is at code 16) I want to set 17, 18 and 19 to be 16 without re-scaling the levels afterwards. In other words, I just want to cut off the end of the dynamic range. Is there a filter to let me do this?

Edit: I see Neuron2 has one here, but for VirtualDub:
http://neuron2.net/coring.html

Last edited by Lyris; 19th October 2014 at 00:52.
Lyris is offline   Reply With Quote
Old 19th October 2014, 01:23   #2  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 4,978
One way is to use masktools, mt_binarize . Probably there are other better ways using luts


Code:
a=WhatEverSource()

a
mt_binarize(19, upper=true) #Y=0 to 19 is the cutoff for the mask
mymask=last

c=blankclip(a, pixel_type="yv12", color=$000000) #create a clip, same characteristics as source, with Y=16

mt_merge(a, c, mymask, true)

But did you want a hard/abrupt cut off at y=19 ? You might get lines where the transition(s) are depending on the content.
poisondeathray is offline   Reply With Quote
Old 19th October 2014, 01:42   #3  |  Link
Lyris
Registered User
 
Join Date: Sep 2007
Location: Europe
Posts: 601
By lines do you mean contouring? Yes, that's possible if the level is set too high. But I want to keep the activity to the part of the picture where it's very hard to see. Thanks!
Lyris is offline   Reply With Quote
Old 19th October 2014, 02:01   #4  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 4,978
Quote:
Originally Posted by Lyris View Post
By lines do you mean contouring? Yes, that's possible if the level is set too high. But I want to keep the activity to the part of the picture where it's very hard to see. Thanks!
I mean a rough transition. A hard line. That's sort of the point of why you are doing this, but if you have content with dark gradients for example, it will be visible and ugly as a sharp line. It really depends on the type of content

This is a binary mask. On/Off. An abrupt cutoff at 19. Normally masks are blended/feathered so the compositing/overlay doesn't look so out of place
poisondeathray is offline   Reply With Quote
Old 19th October 2014, 02:04   #5  |  Link
Lyris
Registered User
 
Join Date: Sep 2007
Location: Europe
Posts: 601
Yes, in fact after seeing your code (thanks a ton BTW) I'm thinking it's better to replace the dark areas with a noise reduced version rather than with pure black. In other words, "calm the dark areas down" to reduce the high frequency and motion content.
Lyris is offline   Reply With Quote
Old 19th October 2014, 02:07   #6  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 4,978
Quote:
Originally Posted by Lyris View Post
Yes, in fact after seeing your code (thanks a ton BTW) I'm thinking it's better to replace the dark areas with a noise reduced version rather than with pure black. In other words, "calm the dark areas down" to reduce the high frequency and motion content.
You can still use the mask technique, and apply the filtered version through the mask

You can use lumamask() function as well, which has a better transition area (not a binary on/off) . Because if you apply clean/filtered version through a hard binary mask, it will look "abrupt" as well

You're essentially now looking at "denoising shadow areas" , which is discussed in many threads.


Code:

function LumaMask(clip filtered, clip raw, int "b", int "w", bool "upper", bool "show"){

raw      = default(raw, filtered)

LO       = string(default(b, 24))
HI       = string(default(w, 48))
upper    = default(upper, false)
show     = default(show,  false)


code     = upper ? "x "+LO+" < 255 x "+HI+" > 0 255 x "+LO+" - 255 "+HI+" "+LO+" - / * - ? ?" : \
                   "x "+LO+" < 0   x "+HI+" > 255 0 x "+LO+" - 255 "+LO+" "+HI+" - / * - ? ?"

msk      = raw.mt_lut(code,u=-128,v=-128)

show  ?  msk : mt_merge(raw, filtered, msk, luma=true, U=3,V=3)}




##############################################################
###                                                          #
### LumaMask() (10-09-2011)                                  #
###                                                          #
##############################################################
###
### Function by Didée, adapted by Dogway:
### http://forum.doom9.org/showpost.php?p=761786&postcount=3
### http://forum.doom9.org/showthread.php?t=158954
###
###
### Mixes 2 versions of a source by a mask defined by luminosity (Luma Plane)
###
###
### filtered [default: last]
### -------------------
### By default the input of the function is assumed as filtered
###
###
### raw [default: filtered]
### -------------------
### Define where you want to create the mask from, and thus blend with the filtered clip.
###
###
### b [default: 24]
### -------------------
### Limit for 100% black in your mask. [0...255]
###
###
### W [default: 48]
### -------------------
### Limit for 100% white in your mask. [0...255]
###
###
### upper [default: false]
### -------------------
### Inverts the mask. By default filtered clip will be passed through the white parts of the mask.
###
###
### show [default: false]
### -------------------
### Shows the mask, which you can directly use with any masking operations on your own.
###
###_______________________
###                       |
### Example:              |
###  raw=last             |
###  YourFilter()         |
###  LumaMask(raw)        |
###_______________________|
###
###   This will pass the filtered version of the clip only in the brightest part of the image,
###   starting where luma pixel value is 24 bright and smoothed up to 100% bypass from 48 brightness value onwards.
###   Useful to protect dark/bright areas from certain filters.
###
###   Requires:
###   Masktools2: http://forum.doom9.org/showthread.php?t=98985
###
##############################################################

Last edited by poisondeathray; 19th October 2014 at 02:10.
poisondeathray 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 03:34.


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