2

Does anyone have experience with defining an input function as threshold criterion for the qtdecomp function in MATLAB? I tried the following but it did not work:

MyFunc = @(A,threshold) std2(A)>threshold;
S = qtdecomp(Image,MyFunc,threshold); 

Somehow, for some threshold values, only the leftmost quarter of the quadtree is divided into new pieces. Could this maybe be an error in the qtdecomp code itself or is there something wrong with my function input?

See the attached image for details. I get this regardless of the threshold I choose:

enter image description here

Adriaan
  • 17,741
  • 7
  • 42
  • 75
S.C. Graaf
  • 21
  • 2
  • We'd really need to see a sample image. This could be expected behavior for some images. Did you try `qtdecomp` without the custom function? – beaker Nov 01 '16 at 21:26

1 Answers1

2

The problem is that the image is passed to your anonymous function as an m x m x k array representing the image decomposed into k blocks. The function must return a vector of length k, but std2 only looks at the first block and returns a scalar. I'm still trying to come up with a vectorized approach to this, but for now here's a simple loop in a standalone function:

function v = Std2Func(A, threshold)
   s = size(A,3);
   v = zeros(1,s);

   for k = 1:s
      v(k) = std2(A(:,:,k))>threshold;
   end   
end

This iterates through the k planes of the input array, applying std2 to each 2d plane and putting the results into the output vector. Then you just call qtdecomp using a handle to the new function:

S = qtdecomp(Image,@Std2Func,threshold);
beaker
  • 16,331
  • 3
  • 32
  • 49