如何在iOS Swift中使用Sobel边缘检测/Canny边缘检测在有限的边缘范围内使用钢笔工具为草图着色? [英] How can I colour my sketch using pen tool within the limited edge boundaries using sobel edge detection/canny edge detection in ios swift?

查看:191
本文介绍了如何在iOS Swift中使用Sobel边缘检测/Canny边缘检测在有限的边缘范围内使用钢笔工具为草图着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GPUImage来检测边缘,并应用GPUImageSobelEdgeDetectionFilter或GPUImageCannyEdgeDetectionFilter.现在我的要求是:

I am using GPUImage to detect the edge and applying GPUImageSobelEdgeDetectionFilter or GPUImageCannyEdgeDetectionFilter . Now my requirement is:

如何从该图像中获取坐标点,以便可以在封闭的边界内绘制图形.

How can I take the coordinate points from that image so that I can make drawing within the closed boundaries.

从图像中检测边缘

Detect Edges from Image

   var image_p: GPUImagePicture?
   var filterImageview: UIImageView! // to display images

   let inputImage = filterImageview.image
    if let anImage = inputImage {
        image_p = GPUImagePicture(image: anImage)
    }

    let filter1 = GPUImageSobelEdgeDetectionFilter()//GPUImageCannyEdgeDetectionFilter()
    image_p?.addTarget(filter1)
    image_p?.processImage()

    let outputImage = filter1.imageFromCurrentlyProcessedOutput()
    filterImageview.image = outputImage

现在,我正在尝试检测点,以便可以在封闭的边界内创建一个单独的图层来进行绘制.

Now I am trying to detect the points so that i can create a separate layer for drawing within the closed boundaries..

  • 例如1.原始图像2.过滤后的sobelEdgeDetection/GPUImageCannyEdgeDetectionFilter图像

  • For example 1. orgnl image 2. filtered sobelEdgeDetection/GPUImageCannyEdgeDetectionFilter image

  1. 2.

我正在使用钢笔工具绘制颜色. 如果我在着色时在圆圈内着色,则在选择其他接触点之前,它不应超出圆圈边界.

I am drawing color using pen tool. If I am coloring inside the circle while coloring, it should not come out of the circle boundary until I choose another touchpoints..

基于接触点,我想在封闭的边界内对其进行着色.

Based on touch point I want to color it within closed boundaries.

我也尝试了Floodfill算法.它给出了不同的输出.不完全是我想要的输出.

I also have tried Floodfill algorithm. It gives the different output. Not exactly my desired output.

我该如何申请?

推荐答案

嘿,Pradip您正在寻找精确的填充算法,它将解决您的问题.

Hey Pradip you are looking for floodfill algorithm to be exact it will solve your problem.

填充算法简要说明-

泛洪填充算法采用三个参数:起始节点,目标颜色和替换颜色.该算法查找通过目标颜色的路径连接到起始节点的数组中的所有节点,并将其更改为替换颜色.

The flood-fill algorithm takes three parameters: a start node, a target color, and a replacement color. The algorithm looks for all nodes in the array that are connected to the start node by a path of the target color and changes them to the replacement color.

为您链接研发以及obejective-c中的演示.

  1. https://lodev.org/cgtutor/floodfill.html
  2. https://github.com/Chintan-Dave/UIImageScanlineFloodfill (很棒的演示礼貌 Chintan-Dave)

  1. https://ilearnios.wordpress.com/2013/07/18/scanline-flood-fill-algorithm-with-or-without-tolerance-in-objective-c/
  2. https://lodev.org/cgtutor/floodfill.html
  3. https://github.com/Chintan-Dave/UIImageScanlineFloodfill (Great demo courtesy of Chintan-Dave)

我还在项目中使用了Floodfill只是为了去除背景色,并且在上面的链接中找到了非常有用的内容. 希望对您有帮助

I have also used floodfill on my project just to remove background colors and found above links veryusefull. Hope it Helps

这篇关于如何在iOS Swift中使用Sobel边缘检测/Canny边缘检测在有限的边缘范围内使用钢笔工具为草图着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆