How can I colour my sketch using pen tool within the limited edge boundaries using sobel edge detection/canny edge detection in ios swift?

廉价感情. 提交于 2019-11-30 18:48:29

问题


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..

  • 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.

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

How could I apply it?


回答1:


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

Floodfill Algorithm Brief Explanation -

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.

Links for you R&D and also a demo in obejective-c.

  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)

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



来源:https://stackoverflow.com/questions/52553432/how-can-i-colour-my-sketch-using-pen-tool-within-the-limited-edge-boundaries-usi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!