小编use*_*293的帖子

使用 python numpy 创建霓虹灯

我正在尝试使用源图像创建霓虹灯效果。我包含了三张图片:来源、我当前的尝试和目标。该程序获取图像,找到白边,并计算每个像素到最近的白边的距离(这些部分都工作正常);从那里开始,我正在努力寻找正确的饱和度和值参数来创建霓虹灯。

从目标图像来看,我需要做的基本上是使白边缘的饱和度为 0,然后随着距离边缘的距离显着增加;对于值,我需要它在白边为 1,然后急剧减小。我无法找出操纵 distance_image (它保存每个像素与最近白边的距离)的最佳方法,例如通过饱和度和值实现这两个结果。

from PIL import Image
import cv2
import numpy as np
from scipy.ndimage import binary_erosion
from scipy.spatial import KDTree

def find_closest_distance(img):
    white_pixel_points = np.array(np.where(img))
    tree = KDTree(white_pixel_points.T)
    img_meshgrid = np.array(np.meshgrid(np.arange(img.shape[0]),
                                        np.arange(img.shape[1]))).T
    distances, _ = tree.query(img_meshgrid)
    return distances

def find_edges(img):
    img_np = np.array(img)
    kernel = np.ones((3,3))
    return img_np - binary_erosion(img_np, kernel)*255

img = Image.open('a.png').convert('L')
edge_image = find_edges(img)
distance_image = find_closest_distance(edge_image)
max_dist = np.max(distance_image)
distance_image = distance_image / max_dist

hue = np.full(distance_image.shape, 0.44*180)
saturation = distance_image * …
Run Code Online (Sandbox Code Playgroud)

python arrays opencv numpy image-processing

2
推荐指数
1
解决办法
871
查看次数

标签 统计

arrays ×1

image-processing ×1

numpy ×1

opencv ×1

python ×1