图像分割 - 分割和合并(四叉树)
图像分割的分割和合并方法有实现吗? 任何建议将不胜感激。
Is there an implementation for the split and merge method of image segmentation?
any advice would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
分割是什么?
分割是指将图像划分为几个相连的区域。基本上,您可以使用两种区域定义进行分割:您可以将区域定义为一组连接的相似像素,或一组被不连续性(边缘)包围的连接像素。拆分和合并使用第一种方法。
从数学上讲:如果您的整个图像由像素集(称为 R)表示,那么您希望获得子集,例如
分割和合并算法是关于什么的?
所以首先,我们必须选择同质性标准。同质性标准可以是全局的(取决于整个区域)或局部的(取决于该区域的一个小窗口,并且如果它对于所有窗口都成立,那么对于该区域也成立)。一个简单的例子是与平均值的偏差应该小于阈值。 ∀pi∈Ri: |pi-μ|≤f*σ。
拆分和合并算法有两个阶段:拆分和合并阶段。
在分割阶段,我们递归地将区域分割为四个子区域(从整个图像作为一个区域开始),直到所有子区域都满足我们的同质性标准。很容易看出满足1-4个分割条件。我们继续合并步骤以满足第五个条件。
在合并步骤中,我们检查每两个相邻区域的 P(Ri U Rj)=TRUE,然后合并这两个区域。我们重复此步骤,直到不需要进行更多更改。现在我们满足了所有条件,我们将图像分割成子区域。
伪代码
这是一个分割和合并算法的伪代码:
What segmentation is about?
Segmentation means division of your image into several connected regions. Basically, you could do segmentation with two definitions of region: you could define a region as a group of connected similar pixels, or a set of connected pixels surrounded by discontinuities (edges). Split and merge uses the first approach.
Mathematically speaking: if your whole image is represented by the set of pixels (called R), than you would like to get subsets such as
What split and merge algorithm is about?
So first, we have to choose a homogenity criterion. A homogenity criterion could be global (depending on the whole region) or local (depending on a small window of the region, and if it's true for all windows, than it's true for the region). A simple example could be the deviation from average should be smaller than a threshold. ∀pi∈Ri: |pi-μ|≤f*σ.
The split and merge algorithm have two phases: the split, and the merge phase.
In the split phase we recursively split regions into four subregions (starting with the whole image as one region) until our homogenity criterion is met in all subregions. It's easy to see that the 1-4 conditions of segmentation are met. We proceed to merge step in order to satisfy the 5th condition.
In the merge step we check that P(Ri U Rj)=TRUE for each two neighbor regions, and merge the two regions. We repeat this step until no more changes are necessary. Now we met all the conditions, we had our image segmented into subregions.
Pseudocode
Here is a pseudocode to split and merge algorithm:
这是我的实现。我不是 c++/opencv 专家,所以如果有人找到一些方法来优化这个脚本,请添加评论!
This is my implementation. I am not a c++ / opencv guru so if someone find out some way to optimize this script add comments please!