View Single Post
Old 21st July 2011, 19:16   #2  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
Version 1.1 of both my LCE as well as my Contrast Mask functions:

Hope you enjoy. LCE should be able to produce similar effects as any unsharp mask, with the difference that it offers different variables to experiment with than radius, amount and threshold. So if the user requires it, it can be less subtle.

# Local Contrast Enhancement:
# a) Blur the original and Create a Local Contrast Mask
# b) Create a higher contrast image out of the original
# c) Mask overlay the higher contrast image to the original, using the Local Contrast Mask.

Example: http://www.cambridgeincolour.com/tut...nhancement.htm

# Photoshop Overlay: "Multiplies or screens the colors, depending on the base color. Patterns or colors overlay the existing pixels while preserving the highlights and shadows of the base color. The base color is not replaced but is mixed with the blend color to reflect the lightness or darkness of the original color."

gblur (exists in LCE and ContrastMask both): the amount of gaussian blur to apply
contrast (LCE only): the amount of contrast to apply
brightness (LCE/mode 0 only): Controls the local brightness effect, valid values from 0.0 to 255.
mode (LCE only): Mode 1 is my attempt at the classic local contrast enhancement technique as it can be implemented by someone using photoshop. Mode 0 can give a similar effect, but the user is free to temper with contrast as well as brightness, not only contrast.
correction (LCE only): Whether to perform a histogram auto-correction. This can improve the LCE even further.
enhance (ContrastMask only): It controls the opacity of the final product. Valid values are from 0.0 to 10.0, where 10.0 is the 100% of the contrast mask.

# *Multiply: (x*y)/255 for PC, (((x-16)*(y-16))/219)+16 for TV
# *Screen: 255-[((255-x)*(255-y))/255] for PC, (219-(((219-(x-16))*(219-(y-16)))/219))+16 for TV
# *Photoshop overlay: If Lower Layer Value > 127.5, Overlay = (Upper Layer Value * Value Unit) + Min Value, where
# Value Unit = (255-Lower Layer Value)/127.5 and Min Value = Lower Layer Value - (255-Lower Layer Value)
# If Lower Layer Value < 127.5, Overlay = Upper Layer Value * Value Unit, where
# Value Unit=Lower Layer Value/127.5

Code:
function LCE(clip v, float "gblur", float "contrast", float "brightness", int "mode", bool "correction")
{
# Local Contrast Enhancement:
# a) Blur the original and Create a Local Contrast Mask
# b) Create a higher contrast image out of the original
# c) Mask overlay the higher contrast image to the original, using the Local Contrast Mask.
brightness = default (brightness, 80)
correction = default (correction, false)
gblur = default (gblur,0.1)
mode = default (mode, 1)
contrast = (mode==1) ? default (contrast, 1.5) : default (contrast, 1.1)
v = (correction==true) ? v.autolevels() : v
brightness = (brightness<=255.0 && brightness>=0.0) ? float(-brightness) : -80
v2=v.Tweak(sat=0)
v2=v2.gaussianblur(gblur)
v2=v2.mt_edge(mode="min/max",thY1=0,thY2=255, Y=3, U=2, V=2)
v3 = (mode==1) ? v.Tweak(cont=contrast) : v.Tweak(cont=contrast,bright=brightness)
merged=mt_merge(v,v3,v2)
return merged
}
I was also doing a Contrast Mask so here goes:

# Contrast Masking:
# a) Desaturate and invert the original.
# b) Apply a Gaussian Blur
# c) Overlay.

Example: http://www.digicamhelp.com/processin...trast-masking/

Code:
function ContrastMask(clip v, float "gblur", float "enhance")
{
enhance = default (enhance, 10.0)
tvcolor = default (tvcolor, true)
gblur = default (gblur, 20.0)
enhance = (enhance>=0.0 && enhance<=10.0) ? float(enhance*0.1) : 1.0
v2=v.Tweak(sat=0)
v2=v2.invert()
v2=v2.gaussianblur(50.0,50.0+gblur)
photoshop_overlay=mt_lutxy(v,v2,"x 127.5 > y 255 x - 127.5 / * x 255 x - - + y x 127.5 / * ? ")
merged=overlay(v,photoshop_overlay,opacity=enhance)
return merged
}
Requirements:
Variableblur (also requires fftw version 3)
mt_masktools
autolevels

Last edited by javlak; 23rd July 2011 at 14:20. Reason: Version 1.1 of LCE
javlak is offline   Reply With Quote