0

I have an big image and I have to :

  • First, apply a function to every possible patch of the image, like a sliding window. This is actually very similar to convolution, which is supported in Matlab, but instead I need to calculate a "key value" (real) on each image patch (let's consider it a black box function). As suggested by the comments, perharps I can use the "blockproc" function

  • Then, I need to find n smallest key values and their respective positions, but the catch is that I have several overlapping windows with similarly low key values then sorting will preserve all of them in the list, which is undesirable. Instead I want to detect those overlapping windows and keep only the one with the lowest key value. You can say that I want to find not the n smallest key values but only the n local minima (not sure if this analogy is correct though) . I can't give the code because it is too long and complicated (face recognition using eigenfaces with +5 functions)

Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
Dang Manh Truong
  • 795
  • 2
  • 10
  • 35
  • 2
    Maybe `blockproc`, maybe `im2col`. It would help tremendously if you actually included a description of what you're trying to do and some sample code that achieves the desired results in your questions. That way we could give more specific answers. – beaker Aug 21 '16 at 15:53
  • 1
    Or `nlfilter`. I forgot about `nlfilter`. Awesome function. – beaker Aug 21 '16 at 15:57
  • @beaker I have edited the question, is it alright now? :( – Dang Manh Truong Aug 21 '16 at 17:38
  • If you want overlapping windows, then `nlfilter` is probably what you want. You just pass it the handle of the function you want to execute on each window. – beaker Aug 21 '16 at 17:42
  • @beaker But it does not seem to be able to solve my second problem :( – Dang Manh Truong Aug 21 '16 at 17:50

1 Answers1

1

Step 1: apply nlfilter to the original image:

keyimg = nlfilter(img, windowsize, keyfun);

Step 2: apply im2col to keyimg and sort key values:

colimg = im2col(keyimg, windowsize, 'sliding');
minimg = sort(colimg, 1); % perhaps take only the first `k` rows
beaker
  • 16,331
  • 3
  • 32
  • 49