I'm trying to implement a Harris corner detector with OpenCv and C++ and I can't seem to find an algorithm to find local maximas, I'm new to image processing, so would you please help me?
Take a 3x3 window, then check if centre pixel is the maximum
I find I am constantly recycling this function from my binary image library https://github.com/MalcolmMcLean/binaryimagelibrary/
/*
get 3x3 neighbourhood, padding for boundaries
Params: out - return pointer for neighbourhood
binary - the binary image
width - image width
height - image height
x, y - centre pixel x, y co-ordinates
border - value to pad borders with.
Notes: pattern returned is
0 1 2
3 4 5
6 7 8
where 4 is the pixel at x, y.
*/
static void get3x3(unsigned char *out, unsigned char *binary, int width, int height, int x, int y, unsigned char border)
{
if(y > 0 && x > 0) out[0] = binary[(y-1)*width+x-1]; else out[0] = border;
if(y > 0) out[1] = binary[(y-1)*width+x]; else out[1] = border;
if(y > 0 && x < width-1) out[2] = binary[(y-1)*width+x+1]; else out[2] = border;
if(x > 0) out[3] = binary[y*width+x-1]; else out[3] = border;
out[4] = binary[y*width+x];
if(x < width-1) out[5] = binary[y*width+x+1]; else out[5] = border;
if(y < height-1 && x > 0) out[6] = binary[(y+1)*width+x-1]; else out[6] = border;
if(y < height-1) out[7] = binary[(y+1)*width+x]; else out[7] = border;
if(y < height-1 && x < width-1) out[8] = binary[(y+1)*width+x+1]; else out[8] = border;
}`
` You might need to change unsigned char to int or float - the function is designed for binary images.