Smoothing a jagged path

∥☆過路亽.° 提交于 2019-11-26 11:23:55
andrew cooke

This is a big subject. You might find Depixelizing Pixel Art1 by Johannes Kopf & Dani Lischinski useful: it's readable, recent, includes a summary of previous work, and explains their approach in detail.

See also slides covering similar background and video(!).

  1. Here are some screenshots from the document of 'nearest neighbor' vs. 'their technique'.

The most general version of this problem is one of the initial stages in most computer vision pipelines. It's called Image Segementation. It splits an image into regions of pixels considered to be visually identical. These regions are separated by "contours" (see for example this article), which amount to paths through the image running along pixel boundaries.

There is a simple recursive algorithm for representing contours as a polyline defined such that no point in it deviates more than some fixed amount (say max_dev) you get to pick. Normally it's 1/2 to 2 pixels.

function getPolyline(points [p0, p1, p2... pn] in a contour, max_dev) {
  if n <= 1 (there are only one or two pixels), return the whole contour
  Let pi, 0 <= i <= n, be the point farthest from the line segment p0<->pn
  if distance(pi, p0<->pn) < max_dev 
    return [ p0 -> pn ]
  else
    return concat(getPolyline [ p0, ..., pi ],  getPolyline [ pi, ..., pn] )

The thought behind this is that you seem to have cartoon-like images that are already segmented. So if you code a simple search that assembles the edge pixels into chains, you can use the algorithm above to convert them into line segment chains that will will be smooth. They can even be drawn with anti-aliasing.

If you already know the segment or edge try blurring with Gaussian or average or one of your own kernel and move to the edge you want to smooth. This is a quick solution and may not suit best in complex images but for self drawn, its good.

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