BrushCue Example: CRT Monitor Filter¶

Open In Colab

You can use this tool online at https://www.brushcue.com/tools/crt-monitor-filter

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

import brushcue as bc

screen_curvature = 0.16
scanline_density = 3.8
scanline_strength = 0.53
rgb_separation = 0.8
glow = 0.17
static_amount = 0.08
edge_darkening = 0.34
input_image = bc.Composition.monet_women_with_parasol()
bounds = input_image.bounds()
curved = input_image.spacial_effect_shader(
    "let uv = (position - bounds_origin) / bounds_size;\nlet centered = uv * 2.0 - vec2f(1.0);\nlet radius_squared = dot(centered, centered);\nlet warped = centered * (1.0 + curvature * radius_squared);\nlet sample_position = bounds_origin + ((warped + vec2f(1.0)) * 0.5) * bounds_size;\nreturn sample(sample_position);",
    "",
    (bounds.width() * screen_curvature),
    bc.Dictionary.create()
    .add("curvature", screen_curvature)
    .add("bounds_origin", bc.Vector2f.from_components(bounds.min_x(), bounds.min_y()))
    .add("bounds_size", bc.Vector2f.from_components(bounds.width(), bounds.height())),
    bc.ColorRepresentation.srgb(),
)
separated = curved.spacial_effect_shader(
    "let min_position = image_bounds.xy + vec2f(0.5);\nlet max_position = image_bounds.zw - vec2f(0.5);\nlet r = sample(clamp(position + vec2f(rgb_separation, 0.0), min_position, max_position)).r;\nlet g = sample(position).g;\nlet b = sample(clamp(position - vec2f(rgb_separation, 0.0), min_position, max_position)).b;\nlet a = sample(position).a;\nreturn vec4f(r, g, b, a);",
    "",
    rgb_separation,
    bc.Dictionary.create()
    .add("rgb_separation", rgb_separation)
    .add("image_bounds", bounds),
    bc.ColorRepresentation.srgb(),
)
displayed = (
    separated.bloom(0.62, 29.0, glow)
    .scanlines(scanline_density, 2.0, 0.0, scanline_strength)
    .film_grain(1.0, 1024.0, 1.0, 512.0, 1.0, 256.0, static_amount)
    .vignette(
        bc.Vector2f.from_components((bounds.width() / 2.0), (bounds.height() / 2.0)),
        (bounds.width() / 2.0),
        (bounds.height() / 2.0),
        (bounds.width() * 0.48),
        edge_darkening,
    )
)
graph = displayed.crop(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