Basic Unsharp Mask filter. Provides even, dispersed sharpening. (This is the opposite of Gaussian Blur.)
class DMJ_UnsharpMask(DMJ_ConvolutionFilter) {
; Basic Unsharp Mask filter. Provides even, dispersed sharpening. (This is the opposite of Gaussian Blur.)
public:
import "common.ulb"
func DMJ_UnsharpMask(Generic pparent)
DMJ_ConvolutionFilter.DMJ_ConvolutionFilter(pparent)
int count = (@p_samples*2+1)
int elements = sqr(count)
setLength(m_Offsets, elements)
setLength(m_Weights, elements)
m_Bias = 0.0
m_Multiplier = 0.0
int j = -@p_samples
int k = 0
int l = 0
float o = 1.0 / (2.0*sqr(@p_samples / 3.0))
while (j <= @p_samples)
k = -@p_samples
while (k <= @p_samples)
m_Offsets[l] = @p_radius*j/@p_samples + flip(@p_radius*k/@p_samples)
m_Weights[l] = -( o/#pi * exp(-(sqr(j)+sqr(k))*o) ) * @p_sharpness
if (j == 0 && k == 0)
m_Weights[l] = m_Weights[l] + 1.0
endif
m_Multiplier = m_Multiplier + m_Weights[l]
l = l + 1
k = k + 1
endwhile
j = j + 1
endwhile
m_Multiplier = 1.0 / m_Multiplier
endfunc
default:
title = "Unsharp Mask"
int param v_dmj_unsharpmask
caption = "Version (DMJ_UnsharpMask)"
default = 100
hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
visible = @v_dmj_unsharpmask < 100
endparam
float param p_sharpness
caption = "Sharpening Amount"
default = 0.25
hint = "Sets the amount of the sharpening effect."
endparam
float param p_radius
caption = "Filter Radius"
default = 0.1
hint = "Sets the radius of the filter. A smaller radius will result in less blurring."
endparam
int param p_samples
caption = "Sample Density"
default = 9
min = 1
hint = "Sets the density of samples used to compute the blur. Increasing the density will dramatically increase the rendering time (increasing with 4x the square of the density) but for very wide blurs you will need to do this to get even blurring."
endparam
}