Edit photo - Oil painting effect - Image manipulation in Python

from skimage import data, io
import random
import sys
from skimage.color import gray2rgb

try:
    rgb_image = data.imread(sys.argv[1])
    height = rgb_image.shape[0]
    width = rgb_image.shape[1]

    if(len(rgb_image.shape) < 3):
        rgb_image = gray2rgb(rgb_image)
   
    for i in range(height):
        for j in range(width):
            for k in range(rgb_image.shape[2]):
                if rgb_image[i,j,k] < 128:
                    rgb_image[i,j,k] = 15
                else:
                    rgb_image[i,j,k] = 240
               
    io.imsave("oil_painting.jpg", rgb_image)
   
except Exception as e:
    print(e)


Original:


Output:

This example applies an oil painting style effect to an image with scikit-image. Effects like this typically replace each pixel with the most common color in its neighborhood, which flattens detail into painterly patches.

It is a good exercise in neighborhood based image processing, where each output pixel depends on a window of surrounding pixels rather than a single one.

Comments

Popular posts from this blog

[Solved] Error: No such keg: /usr/local/Cellar/gcc

[How To] Unfollow Non-followers on Instagram