BrushCue Example: RGB Color Shift¶
You can use this tool online at https://www.brushcue.com/tools/rgb-color-shift
In [ ]:
!pip install brushcue
In [1]:
import io
from PIL import Image
import brushcue as bc
input_image = bc.Composition.monet_women_with_parasol()
displacement = 1.0
green_offset = bc.Vector2i.from_components(
bc.Float.round_to_int((84.0 * displacement)),
bc.Float.round_to_int((30.0 * displacement)),
)
blue_offset = bc.Vector2i.from_components(
bc.Float.round_to_int(((-56.0) * displacement)),
bc.Float.round_to_int(((-69.0) * displacement)),
)
crop_x_component = green_offset.x().abs().max(blue_offset.x().abs())
crop_y_component = green_offset.y().abs().max(blue_offset.y().abs())
bounds = input_image.bounds()
crop_width = bc.Vector2i.from_components(
bounds.width().round_to_int(), bounds.height().round_to_int()
).x() - (crop_x_component * 2)
bounds_2 = input_image.bounds()
crop_height = bc.Vector2i.from_components(
bounds_2.width().round_to_int(), bounds_2.height().round_to_int()
).y() - (crop_y_component * 2)
graph = (
input_image.linear_transform(
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0
)
.blend_add(
input_image.linear_transform(
0.0,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0,
).blend_add(
input_image.linear_transform(
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0,
),
bc.Transform2.identity().translation(
bc.Vector2f.from_components(
green_offset.x().to_float(), green_offset.y().to_float()
)
),
),
bc.Transform2.identity().translation(
bc.Vector2f.from_components(
blue_offset.x().to_float(), blue_offset.y().to_float()
)
),
)
.crop(
bc.Bounds2f.from_x_y_width_height(
crop_x_component.to_float(),
crop_y_component.to_float(),
crop_width.to_float(),
crop_height.to_float(),
)
)
)
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 Metal — adapter 'Apple M5' (IntegratedGpu), driver ''
Out[1]: