您的位置:首页 > 运维架构

Photoshop中的“磁性套索”背后算法的OpenCV实现

2016-09-29 20:27 1531 查看
本文由Markdown语法编辑器编辑完成。

1. PS中的磁性套索工具简介:

本示例是基于Photoshop CS4的工具栏:







2. 磁性套索工具背后的算法Livewire原理:

3. Livewire Segmentation简介及其OpenCV的实现:

3.1 Livewire简介:

Livewire, also known as Intelligent Scissors, is a segmentation technique which allows a user to select regions of interst to be extracted quickly and accurately using a relatively small number of mouse clicks. There are many variation on livewire, but perhaps the best known example is the “magnetic lasso” tool in Photoshop. Even more sophisticated versions may take into account training data and/or lines drawn around images from neighboring slices or frames (in the case of 3D image data or animation). Livewire can be a huge help in quick image segmentation.

3.2 Livewire的算法原理:

Livewire typically works as two stage process:

(1) The entire image must be filtered using filters such as the Median filter, and/or edge detection algorithms such as the Sobel filter and converted to grayscale(灰阶) such that black regions represent the most desirable paths.

(2) A lowest cost path algorithm(最短路径算法), such as Dijkstra’s algorithm, is applied to the modified image to find the best path from one point, to another. In resulting “graph” each pixels is a node with edges going to the 4 (up, down, left, right) or 8 pixels around it and the edge costs are defined on a cost function based on the pixel value, and possibly other factors.

综上,磁性套索的基本原理应该是:

对读入的图像,首先进行中值滤波,然后进行边缘提取,输出为一个只有边缘的灰阶图像,然后再利用图论中的最短路径算法,去寻找两个点之间的最短路径。那么这个最短路径就是磁性套索中检测到的两个点区域内的边缘(最短路径)。

基于以上,可以采用VTK中的 高斯滤波或中值滤波 + 边缘提取 + 最短路径来实现。有机会可以试验一下。

参考链接:

1. Livewire介绍:

http://www.pudn.com/downloads212/sourcecode/graph/texture_mapping/detail998873.html

2. 源码地址:

http://en.pudn.com/downloads368/sourcecode/graph/texture_mapping/detail1593060_en.html

http://www.pudn.com/downloads212/sourcecode/graph/texture_mapping/detail998873.html

3. ITK之livewire:

http://www.insight-journal.org/browse/publication/230

未完待续……
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: