File size: 1,906 Bytes
4f6789c
 
 
 
 
 
 
 
 
74f19b4
 
 
 
4f6789c
 
 
 
 
 
74f19b4
 
 
 
4f6789c
 
 
 
 
74f19b4
 
 
 
4f6789c
 
 
 
 
74f19b4
 
 
 
 
4f6789c
 
 
 
 
 
 
74f19b4
4f6789c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# "Production code"
import numpy as np
from interactive_pipe import Curve, SingleCurve

# -----------------
# Processing blocks
# -----------------


def gen_color(
    frequency: int = 0,  # discrete slider (int)
    isotropy: float = 0.,  # continuous slider (float)
) -> np.ndarray:
    lin_coord = np.linspace(0, 1., 256)
    X, Y = np.meshgrid(lin_coord, isotropy*lin_coord)
    radius = 0.5+0.5*np.cos(frequency*np.sqrt(X**2 + Y**2))
    return np.stack([np.abs(X), np.abs(Y), radius], axis=-1).clip(0, 1)


def modify_geometry(
    img: np.ndarray,
    effect: str = "flip"  # dropdown menus (str)
) -> np.ndarray:
    img = img[::-1] if "flip" in effect else img
    img = img[:, ::-1] if "mirror" in effect else img
    return img


def change_color(
    img: np.ndarray,
    bnw: bool = True  # checkboxes (bool)
):
    if bnw:
        return np.mean(img, axis=-1, keepdims=True).repeat(3, axis=-1)
    return img


def compare_by_splitting(
    img_1: np.ndarray,
    img_2: np.ndarray,
    ratio: float = 0.5,  # continuous slider (float)
) -> np.ndarray:
    out = np.zeros_like(img_1)
    split = int(ratio*img_1.shape[1])
    out[:, :split] = img_2[:, :split]
    out[:, split+5:] = img_1[:, split+5:]
    return out


def extract_profile(img: np.ndarray,) -> Curve:
    luma = img.mean(axis=-1)
    h_profile = SingleCurve(y=luma[0, :], label="H profile")
    v_profile = SingleCurve(y=luma[:, 0], label="V profile")
    return Curve(
        [h_profile, v_profile],
        xlabel="Position", ylabel="Luminance",
        grid=True
    )

# -------------------
# Pipeline definition
# -------------------


def tutorial_pipeline():
    inp = gen_color()
    out_geometry = modify_geometry(inp)
    out_bnw = change_color(inp)
    out_image = compare_by_splitting(out_geometry, out_bnw)
    out_profile = extract_profile(out_image)
    return [[inp, out_geometry], [out_profile, out_image]]