“不在乎"用于二进制形态树修剪的内核中的元素,MATLAB [英] "Don't care" elements in kernel used for binary morphological tree pruning, MATLAB

查看:78
本文介绍了“不在乎"用于二进制形态树修剪的内核中的元素,MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修剪数字(0-9)的骨架化图像,由于原始数字厚度的不规则性,有时会高度分支该分支图像.

I am trying to prune a skeletonized image of numbers (0-9), which is sometimes highly branched because of irregularities in the original number thickness.

为此,我尝试使用图4中所示的内核:

For this, I am trying to use the kernels shown in Fig. 4: http://homepages.inf.ed.ac.uk/rbf/HIPR2/thin.htm, which contain "don't care" cells.

因为我看不到如何在内核中编写无关"元素的代码,所以我在考虑无关"元素的同时创建了其他内核来掩盖所有可能性.但是,由于计算量大,这极大地增加了代码的复杂性.例如,请考虑图4中的第一个内核:

Because I don't see how to code a "don't care" element in a kernel, I am creating other kernels to cover up all of the possibilities when taking into account the "don't care" elements. However, this greatly increases the complexity of the code, as it is computationally expensive. For example, take into account the first kernel in Fig 4:

kernel1 = [1 1 1; * 1 *; 0 0 0] -->

[1 1 1; 1 1 0; 0 0 0]
[1 1 1; 0 1 1; 0 0 0]
[1 1 1; 1 1 1; 0 0 0]
[1 1 1; 0 1 0; 0 0 0]

其中*表示无关"元素.直接编码无关"元素将不那么麻烦,并且将大大减少计算时间.

Where * denotes "don't care" elements. Directly coding a "don't care" element would be much less cumbersome, and it would largely decrease computation time.

有人对此有任何建议吗?

Does anyone have any suggestions on how to deal with this?

维克多

推荐答案

我想向您展示我的方法:

I'd like to show you my approach:

实际上,您需要创建一个矩阵,其中行由所有已知列(10)和未知列-*组成.对于所有未知元素,我们需要创建具有所有可能组合的行. 因此,我们可以找到*的数量,创建具有所有可能组合的表,并将其与已知列组合.例如(根据您的数据):

Really you need to create an matrix with rows consist of all known columns (1 and 0) and unknown - *. For all unknown elements we need to create rows with all possible combinations. So, we can find number of *, create a table with all possible combinations and combine it with known columns. For example (from your data):

[* 1 *] 
   to
[1 1 0;
 0 1 1;
 1 1 1;
 0 1 0]

或者按照我的方法:我们有2个*,所以我们需要创建两个元素的所有组合的矩阵:

Or in my approach: we have 2 * so we need to create matrix of all combinations of two elements:

A =[ 0 0;                      B = [ 1;
     0 1;    and combine with        1;
     1 0;                            1;
     1 1 ]                           1 ]

组合:

result = [ A(:,1) B A(:,2)]

这是简单的操作.仅一个问题:如何创建此矩阵A. 让我们这样走吧:

This are easy operations. Only one question: how to create this matrix A. Let's go this way:

我不知道您的矩阵的数据类型,但是在数字形式中,我们不能使用*符号.因此,我将改用-1. (如果您有符号数组或单元格数组,则很容易将其转换为数字数组,因此我的示例仍然可以工作,只需要添加几个转换操作). 更多细节-让我们不仅为3元素行解决问题,而且为n解决问题.所以我们有

I don't know datatype of your matrix, but in numeric we can't use * symbol. So, I will use -1 instead. (If you have symbolic or cell arrays it's easy to convert it to numeric, so my example still works just need to add several converting actions). One more detail - let's solve your problem not only for 3-element row, but for n. So we have

A = [1 -1 -1 -1]
n = numel(find(A==-1))
func = @(x,n) repmat( [ ones(1, 2.^(n-x)) zeros(1, 2.^(n-x)) ] , 1, 2.^(x-1))
ind = [1:n]'    %'
result = cell2mat ( arrayfun(func,ind,n*ones(1,n)','UniformOutput',false) )'  

结果:

result =

 1     1     1
 1     1     0
 1     0     1
 1     0     0
 0     1     1
 0     1     0
 0     0     1
 0     0     0


检查您的示例:


Check your example:

A = [-1 1 -1]
result =

     1     1
     1     0
     0     1
     0     0

这篇关于“不在乎"用于二进制形态树修剪的内核中的元素,MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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