Log in

View Full Version : How to set just-above-black shades to black? (Coring?)


Lyris
19th October 2014, 00:49
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

poisondeathray
19th October 2014, 01:23
One way is to use masktools, mt_binarize . Probably there are other better ways using luts




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.

Lyris
19th October 2014, 01:42
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!

poisondeathray
19th October 2014, 02:01
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

Lyris
19th October 2014, 02:04
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.

poisondeathray
19th October 2014, 02:07
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.





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
###
##############################################################