Sunday, February 19, 2017

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:

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.