Python 带PIL的图像上的羽状边缘

Python 带PIL的图像上的羽状边缘,python,image,image-processing,python-imaging-library,pillow,Python,Image,Image Processing,Python Imaging Library,Pillow,如何使用枕头创建羽毛边缘效果? 我所说的羽化边缘是指边缘以一种随背景褪色的方式软化,这看起来更像下图: 我试着用以下方法模糊: im.filter(ImageFilter.BLUR) 但是边缘保持清晰。我不确定你想要的是模糊图像。我的印象是,你所描述的是,图像的边缘变得越来越透明。可以通过创建和操纵alpha通道来调整透明度。由于您使用的是Python,下面是一个使用Python、numpy和scikit image中的宇航员图像的示例。alpha通道定义为中心恒定(无透明度),边缘为零(透明

如何使用枕头创建羽毛边缘效果? 我所说的羽化边缘是指边缘以一种随背景褪色的方式软化,这看起来更像下图:

我试着用以下方法模糊:

im.filter(ImageFilter.BLUR)

但是边缘保持清晰。

我不确定你想要的是模糊图像。我的印象是,你所描述的是,图像的边缘变得越来越透明。可以通过创建和操纵alpha通道来调整透明度。由于您使用的是Python,下面是一个使用Python、numpy和scikit image中的宇航员图像的示例。alpha通道定义为中心恒定(无透明度),边缘为零(透明),中间为线性渐变。您可以调整alpha通道,以便在无透明度和完全透明度之间实现更平滑、更清晰的过渡

import numpy as np
from skimage import data

astro = data.astronaut()
l_row, l_col, nb_channel = astro.shape
rows, cols = np.mgrid[:l_row, :l_col]
radius = np.sqrt((rows - l_row/2)**2 + (cols - l_col/2)**2)
alpha_channel = np.zeros((l_row, l_col))
r_min, r_max = 1./3 * radius.max(), 0.8 * radius.max()
alpha_channel[radius < r_min] = 1
alpha_channel[radius > r_max] = 0
gradient_zone = np.logical_and(radius >= r_min, radius <= r_max)
alpha_channel[gradient_zone] = (r_max - radius[gradient_zone])/(r_max - r_min)
alpha_channel *= 255
feathered = np.empty((l_row, l_col, nb_channel + 1), dtype=np.uint8)
feathered[..., :3] = astro[:]
feathered[..., -1] = alpha_channel[:]

import matplotlib.pyplot as plt
plt.imshow(feathered)
plt.show()
将numpy导入为np
从浏览导入数据
astro=数据。宇航员()
l_行、l_列、nb_通道=天文形状
行,列=np.mgrid[:l_行,:l_列]
半径=np.sqrt((行-l_行/2)**2+(列-l_列/2)**2)
alpha_通道=np.零((l_行,l_列))
r_min,r_max=1./3*radius.max(),0.8*radius.max()
alpha_通道[半径r_最大值]=0

梯度区=np.逻辑区和(radius>=r_min,radius我不确定您想要的是模糊图像。我的印象是,您描述的是图像对图像边缘越来越透明。您可以通过创建和操作alpha通道来调整透明度。因为您使用的是Python,下面是一个使用Python的示例,numpy和scikit图像中的宇航员图像。alpha通道定义为中心恒定(无透明度),边缘为零(透明),中间为线性渐变。您可以调整alpha通道,使其在无透明度和完全透明之间实现更平滑、更锐利的过渡

import numpy as np
from skimage import data

astro = data.astronaut()
l_row, l_col, nb_channel = astro.shape
rows, cols = np.mgrid[:l_row, :l_col]
radius = np.sqrt((rows - l_row/2)**2 + (cols - l_col/2)**2)
alpha_channel = np.zeros((l_row, l_col))
r_min, r_max = 1./3 * radius.max(), 0.8 * radius.max()
alpha_channel[radius < r_min] = 1
alpha_channel[radius > r_max] = 0
gradient_zone = np.logical_and(radius >= r_min, radius <= r_max)
alpha_channel[gradient_zone] = (r_max - radius[gradient_zone])/(r_max - r_min)
alpha_channel *= 255
feathered = np.empty((l_row, l_col, nb_channel + 1), dtype=np.uint8)
feathered[..., :3] = astro[:]
feathered[..., -1] = alpha_channel[:]

import matplotlib.pyplot as plt
plt.imshow(feathered)
plt.show()
将numpy导入为np
从浏览导入数据
astro=数据。宇航员()
l_行、l_列、nb_通道=天文形状
行,列=np.mgrid[:l_行,:l_列]
半径=np.sqrt((行-l_行/2)**2+(列-l_列/2)**2)
alpha_通道=np.零((l_行,l_列))
r_min,r_max=1./3*radius.max(),0.8*radius.max()
alpha_通道[半径r_最大值]=0

梯度区=np.逻辑区和(radius>=r_min,radius我不认为PIL/Pillow内置了这种功能。但是,如果你能弄清楚你必须使用什么内核才能达到这种效果,我认为应该有一种方法将它应用到你的图像中。我不认为PIL/Pillow内置了这种功能。但是,如果你能弄清楚你必须使用什么内核才能达到这种效果,我认为应该有一种方法把它应用到你的形象上。