Color Examples

[1]:
from easycv import Image, Pipeline
from easycv.transforms import GrayScale, Sepia, FilterChannels, GammaCorrection, Negative, Cartoon, PhotoSketch, ColorTransfer, Colorize, ColorPick, Quantitization, Hue, Contrast, Brightness, Hsv

For this example we will load an image with random(). For more examples of image loading check Image examples.

[2]:
img = Image.random()
img
[2]:
../../_images/examples_transforms_color_3_0.png

Gray Scale

To convert the image to grayscale we just need to apply the transform, for more information check the reference.

[3]:
img.apply(GrayScale())
[3]:
../../_images/examples_transforms_color_6_0.png

Sepia

To convert the image to grayscale we just need to apply the transform, for more information check the reference.

[4]:
img.apply(Sepia())
[4]:
../../_images/examples_transforms_color_9_0.png

Filter Channels

To remove a channel we just need to apply the transform with a list of the channels to remove, for more information check the reference.

[5]:
img.apply(FilterChannels(channels=[1]))
[5]:
../../_images/examples_transforms_color_12_0.png

Gamma Correction

To apply gamma correction we just need to apply the transform with a new gamma value, for more information check the reference.

[6]:
img.apply(GammaCorrection(gamma=3.0))
[6]:
../../_images/examples_transforms_color_15_0.png
[7]:
img.apply(GammaCorrection(gamma=0.5))
[7]:
../../_images/examples_transforms_color_16_0.png

Negative

To convert the image to negative we just need to apply the transform, for more information check the reference.

[8]:
img.apply(Negative())
[8]:
../../_images/examples_transforms_color_19_0.png

Cartoon

To make an image look like a Cartoon we just need to apply the transform, for more information check the reference.

[9]:
img.apply(Cartoon())
[9]:
../../_images/examples_transforms_color_22_0.png

Photo Sketch

To make an image look like a pencil sketch we just need to apply the transform, for more information check the reference.

[10]:
img.apply(PhotoSketch())
[10]:
../../_images/examples_transforms_color_25_0.png

Color Transfer

To transfer the colors from source to target we just need to apply the transform, for more information check the reference.

[11]:
src = Image("images/source.jpg")
src
[11]:
../../_images/examples_transforms_color_28_0.png
[12]:
img.apply(ColorTransfer(source=src))
[12]:
../../_images/examples_transforms_color_29_0.png

Color Pick

To pick the color from the desired point or rectangle we just need to apply the transform, for more information check the reference.

[13]:
img.apply(ColorPick(method="point"))
[13]:
{'color': [127, 116, 120]}

Colorize

To colorize an image apply the Colorize transform to a grayscale image, for more information check the reference.

[14]:
gray = img.apply(GrayScale())
gray
[14]:
../../_images/examples_transforms_color_35_0.png
[15]:
gray.apply(Colorize())
[15]:
../../_images/examples_transforms_color_36_0.png

Quantitization

To reduce the number of colors of an image apply the Quantitization with the number of colors, for more information check the reference.

[16]:
img.apply(Quantitization(clusters=8))
[16]:
../../_images/examples_transforms_color_39_0.png

Hue

To add hue to an image apply the Hue with the value to add, for more information check the reference.

[17]:
img.apply(Hue(value=10))
[17]:
../../_images/examples_transforms_color_42_0.png

Contrast

To add contrast to an image apply the Contrast with alpha value of contrast to add, for more information check the reference.

[18]:
img.apply(Contrast(alpha=1.4))
[18]:
../../_images/examples_transforms_color_45_0.png

Brightness

To add brightness to an image apply the Brightness brightness to add, for more information check the reference.

[19]:
img.apply(Brightness(beta=10))
[19]:
../../_images/examples_transforms_color_48_0.png

Hsv

To reduce the number of colors of an image apply the Quantitization with the number of colors, for more information check the reference.

[20]:
img.apply(Hsv())
[20]:
../../_images/examples_transforms_color_51_0.png