Edit photo - Picture frame - Image effects in Python

from skimage import data, io
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,j in zip(range(int(width/8)), range(int(width/8),0,-1)):
        rgb_image[i, 0:j, :] = 0
   
    for i,j in zip(range(int(7*(height/8)),height), range(0,int(width/8))):
        rgb_image[i, 0:j, :] = 0
   
    for i,j in zip(range(int(width/8)), range(int(7*(width/8)),width)):
        rgb_image[i, j:width, :] = 0
   
    for i,j in zip(range(int(7*(height/8)),height), range(width,int(7*(width/8)),-1)):
        rgb_image[i, j:width, :] = 0

    io.imsave("frame_image.jpg", rgb_image)
   
except Exception as e:
    print(e)


Input:

Output:

This example adds a decorative border, or picture frame, around an image using scikit-image. The idea is to draw colored pixels along the edges, or pad the array, so the photo sits inside a frame.

It is a simple introduction to working with image coordinates and borders, and the same indexing approach extends to watermarks and overlays.

Comments

Popular posts from this blog

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

[How To] Unfollow Non-followers on Instagram