如何获得单线/曲线的边缘?

问题描述 投票:0回答:1

这是我第一次使用图像处理。在木星笔记本中,我尝试使用scipy将灰度线条艺术图像转换为SVG矢量表示。到目前为止,我已经能够将灰度图像转换为二进制图像(单色图像),并在x和y轴上使用sobel滤波器来获取图形的边缘。我得到双线作为边缘来说明线的两边(如下图所示以及我使用的代码)

我想用单行替换这些双行。之后,检测图形中的线和曲线并将其转换为svg线和贝塞尔曲线。在网上搜索时,我对正确的前进方式有点不知所措和困惑。如果我能从这里获得一些有关如何进行的指示,那将有很大的帮助。如果可能的话,我只想使用scipy而不是使用opencv。

而不是简单地使用现有的scipy函数和算法,我还想了解基础理论,以便我可以有效地使用它们。因此,请分享任何有用的理论资源。

提前感谢

enter image description here

%matplotlib inline

import numpy as np
from scipy import ndimage as nd
import matplotlib.pyplot as plt
from skimage import io

def apply_gradient_threshold(d,thres):
    d2 = np.copy(d)
    d2[d2 == -thres] = thres
    d2[d2 != thres] = 0
    return d2


def plot_images(imgs, names):
    fig, axes_list =  plt.subplots(1, len(imgs), figsize=(20, 20))
    for name,axes in zip(names, axes_list):
        axes.set_title(name)

    for img, axes in zip(imgs, axes_list):
        axes.imshow(img, cmap='Greys_r')

    plt.show()  

img_file = <file_url>

img = plt.imread(img_file)
gray_img = io.imread(img_file, as_gray=True) 

if(np.max(gray_img) > 1) :
    gray_img = gray_img/255 #normalize

threshold = 0.2
binary = (gray_img > threshold)*1  # convert the grayscale image to binary (monochrome)

im = binary.astype('int32')
dx = nd.sobel(im,1)
dy = nd.sobel(im,0)
dx = apply_gradient_threshold(dx, 4)
dy = apply_gradient_threshold(dy, 4)
mag = np.hypot(dx,dy) #sqrt(dx^2 + dy^2)
mag *= 255.0/np.max(mag)

plot_images([binary, mag ], ['Binary - ' + str(threshold), 'Sobel Filter Result'])
image-processing scipy convolution edge-detection
1个回答
0
投票

您的图像实际上已经由边缘组成。使用细化,而不是边缘过滤器。

© www.soinside.com 2019 - 2024. All rights reserved.