簡體   English   中英

使用 python 為非矩形圖像添加羽毛效果

[英]Add feather effect to non-rectangular images using python

我想將羽化效果應用到圖像的邊緣。 這是一個例子

使用矩形圖像非常簡單。 但是我無法在非矩形圖像(具有透明背景的圖像)上找到一種方法。 這是一個例子

我用 opencv 和 PIL 嘗試了各種方法,但沒有運氣。 請幫我解決一下這個。 謝謝。

import numpy as np
import cv2
# import the image
input_image = cv2.imread('VagcO.png')
# get the number of rows & columns in m & n respectively 
n , m = input_image.shape[0], input_image.shape[1]
# copy the image for image processing
output = np.copy(input_image)
# loop on RGB channels
for layer in range(3):
    value = 255
    # loop for bottom of image only 15 rows pixel
    for row in reversed(range(n)[n-15:]):
        # loop for every column pixel in that row
        for column in range(m):
            # checking if every pixel is zero for usualy for background of images
            if output[row,column,0]==0 and output[row,column,1]==0 and output[row,column,2]==0:
                # skip that pixel
                continue
            # chaning the value to 255 and decrementing on every iteration
            output[row,column,layer] = value 
        value = value - 2
        
cv2.imshow('Original', input_image)
# crop the image to apply the bluring filter
cropedImage = output[n-20:, :, :]
mask = cv2.GaussianBlur(mask, (9,9), sigmaX=1, sigmaY=10, borderType = cv2.BORDER_DEFAULT)       
# remaning part of image
output = output[:n-20, : , :]
# adding both part into one image
feathredimg = np.concatenate((output, cropedImage), axis=0)
cv2.imshow("Freathred Image", feathredimg)
cv2.waitKey(0)
cv2.destroyAllWindows() 

我為給定的問題創建了解決方案。 看一看。 希望這能有所幫助。 此代碼與給定的示例圖像完美配合。 在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM