3

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.

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.

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?

Victor

  • Is using `NaN` for `*` an option? You could then use an `isnan`-generated mask within your computation to filter which elements you actually care about. – Mad Physicist Dec 23 '15 at 14:42

2 Answers2

1

Thank you for your answer!

With the help of your 'result' outcome, I was able to generate all possible matrices for any number of 'don't care' elements, n. This helped out a lot!

(If anyone's interested: )

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) )'

[row,col] = find(A == -1)

for i = 1:size(result,1)
     for b = 1:size(result,2)
         output{i}(row(b),col(b)) = result(i,b);
     end
     output{i} = abs(new{i} + A + isnan(A));
end

Thanks again!

  • It was inserting problem! I upvote your question and answer! :) By he way, maybe your solution can be improved for avoid using loops! – Mikhail_Sam Dec 24 '15 at 08:58
0

I'd like to show you my approach:

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]

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 ]

Combining:

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

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

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:

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
Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
  • Hmmm... After I post my answer, I reread your question and think around... Maybe you meant not to create all possible `don't care` element but create exactly you need?.. And maybe I solved already solved problem? :D – Mikhail_Sam Dec 23 '15 at 14:39