Spaces:
Sleeping
Sleeping
| from interactive_pipe import interactive_pipeline, interactive | |
| from interactive_pipe import Curve, SingleCurve | |
| import numpy as np | |
| def gen_color(frequency=0, isotropy=0.): | |
| 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, effect="flip"): | |
| img = img[::-1] if "flip" in effect else img | |
| img = img[:, ::-1] if "mirror" in effect else img | |
| return img | |
| def change_color(img, bnw=True): | |
| if bnw: | |
| return np.mean(img, axis=-1, keepdims=True).repeat(3, axis=-1) | |
| return img | |
| def split(img_1, img_2, ratio=0.5): | |
| 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 profile(img): | |
| 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") | |
| markdown_description = "# Code to build this app on gradio \n" | |
| markdown_description += "```python\n"+open(__file__, 'r').read()+"```" | |
| def simple_pipe(): | |
| inp = gen_color() | |
| out_geometry = modify_geometry(inp) | |
| out_bnw = change_color(inp) | |
| out_image = split(out_geometry, out_bnw) | |
| out_profile = profile(out_image) | |
| return [inp, out_geometry, out_profile, out_image] | |
| if __name__ == "__main__": | |
| simple_pipe() | |