Search code examples
javaalgorithmimage-processingpseudocode

Pseudo-Code non-maximum suppression


I have to find an maximum in an Octave with a 3x3x3 neighborhood. That means I have four layers on top of each other and between this layers i have to find a maxima. For illustration here an image. That is not what Iam doing but it represent what is my issue.

Octave layer image http://docs.opencv.org/trunk/_images/sift_dog.jpg

Now for the maximum surpression I found thi paper: Efficient Non-Maximum Suppression. Here is an fast way explained to find a maxima in an Image. This is only the 2D case but it shouldn't be a problem to shift this in 3D space. My problem now is really the pseudo code understanding. I have the pseudo-code:

Pseudo-Code

The problem is the red marked part. There I have for loop but I have no idea how to apply the "-[i, i+n] x [j, j+n]" to the loop. That is the moment solution:

//find local maxima after paper implementation not finished yet
private  Vector<Integer>  FindLocalMaximum(Image image)
{
     Vector<Integer> list = new Vector<Integer>();
       int n = 1;
       int step = 2*n + 1;

       for(int i = n; i < image.GetWidth()-n; i =step)
           for(int j = n; j < image.GetHeight()-n; j =step)
           {
               int mi = i;
               int mj = j;

               for(int i2 = i; i2 < i + n; i2++  )
                   for(int j2 = j; j2 < j + n; j2++  )
                       if(image.GetPixel(i2, j2) > image.GetPixel(mi, mj))
                       {
                           mi = i2;
                           mj = j2;
                       }
               boolean found = true;
               failed:
               for(int i2 = mi - n; i2 < mi + n; i2++  )
                   for(int j2 = mj - n; j2 < mj + n; j2++  )
                       if(image.GetPixel(i2, j2) > image.GetPixel(mi, mj))
                       {
                           found = false;
                           break failed;
                       }

              if(found)
              {
                  int pos = mj * image.GetWidth() + mi;
                  list.add(pos);
              }
           }

   return list;
}

So how surprise it doesn't work. Has somebody an idea what I have to do at the red marked part.


Solution

  • I'll give you an example in pseudocode:

    listA = [1, 2, 3]
    listB = [a, b, c]
    
    listA x listB = [(1, a), (1, b), (1, c), ...]
    
    # excluded
    listAe = [1, 3]
    listBe = [a, b]
    
    listAe x listBe = [(1, a), (1, b), ...]
    
    # result
    listA x listB - listAe x listBe = [(1, c), (2, a), (2, b), (2, c), (3, c)] 
    

    Now you should only iterate over result pairs.