Pipeline examples¶
[1]:
from easycv import Image, Pipeline
from easycv.transforms import Gradient, Blur, Rotate
For this example we will load an image using random().
[2]:
img = Image.random()
img
[2]:
Creating pipeline¶
To create a pipeline we simply call it’s constructor with a list of transforms.
[3]:
pipeline = Pipeline([Gradient(), Blur()], name="test")
pipeline
[3]:
Pipeline (test) with 2 transforms
1: Gradient (axis=x, method=sobel, size=5)
2: Blur (method=gaussian, size=auto, sigma=0, sigma_color=75, sigma_space=75, truncate=4)
[4]:
img.apply(pipeline)
[4]:
We can also create a pipeline with another pipeline inside
[5]:
pipeline = Pipeline([pipeline, Rotate(degrees=20)],name="test")
pipeline
[5]:
Pipeline (test) with 3 transforms
1: Pipeline (test) with 2 transforms
| 1: Gradient (axis=x, method=sobel, size=5)
| 2: Blur (method=gaussian, size=auto, sigma=0, sigma_color=75, sigma_space=75, truncate=4)
2: Rotate (degrees=20, scale=1, center=auto, original=True)
And it’s possible to add a transform to an existing pipeline
[6]:
pipeline.add_transform(Rotate(degrees=-40))
pipeline
[6]:
Pipeline (test) with 4 transforms
1: Pipeline (test) with 2 transforms
| 1: Gradient (axis=x, method=sobel, size=5)
| 2: Blur (method=gaussian, size=auto, sigma=0, sigma_color=75, sigma_space=75, truncate=4)
2: Rotate (degrees=20, scale=1, center=auto, original=True)
3: Rotate (degrees=-40, scale=1, center=auto, original=True)
Number of transforms¶
You can check the number of transforms in a pipeline. This is the number of Transforms so nested pipelines count as their internal number of Transforms
[7]:
pipeline.num_transforms()
[7]:
4
Clear¶
You can also remove every transform in a pipeline
[8]:
pipeline.clear()
pipeline.num_transforms()
[8]:
0
Save¶
If you want you can save a pipeline for future use or sharing
[9]:
pipeline.save(filename="pipeline")