BrushCue Example: Unsharp Mask¶

Open In Colab

You can use this tool online at https://www.brushcue.com/tools/unsharp-mask

In [ ]:
!pip install brushcue
In [1]:
import io
from PIL import Image

import brushcue as bc

amount = 1.5
radius = 2.0
threshold = 0.02
input_image = bc.Composition.monet_women_with_parasol()
input_bounds = input_image.bounds()
blurred = input_image.gaussian_blur(radius).crop(input_bounds)
graph = input_image.spacial_effect_shader(
    "let original = sample(position);\nlet blurred = sampleBlurred(position);\nlet detail = original.rgb - blurred.rgb;\nlet magnitude = max(abs(detail.r), max(abs(detail.g), abs(detail.b)));\nlet gate = smoothstep(threshold, threshold + 0.02, magnitude);\nlet sharpened = clamp(original.rgb + detail * amount * gate, vec3<f32>(0.0), vec3<f32>(1.0));\nreturn vec4<f32>(sharpened, original.a);",
    "",
    0.0,
    bc.Dictionary.create()
    .add("amount", amount)
    .add("threshold", threshold)
    .add("blurred", blurred),
    bc.ColorRepresentation.srgb(),
).crop(input_bounds)

ctx = bc.Context()
composition = graph.execute(ctx)
data_bytes = composition.to_image_bytes(ctx)
img = Image.open(io.BytesIO(data_bytes))
img.thumbnail((400, 400))  # Remove this line for full resolution
img
[wgpu] using backend Vulkan — adapter 'NVIDIA GeForce RTX 5070' (DiscreteGpu), driver '
NVIDIA'
Out[1]:
No description has been provided for this image