Correlation Implementation

asked 2016-10-13 03:55:58 -0600

kevgeo gravatar image

updated 2020-10-25 07:35:38 -0600

I want to basically write code from scratch to do correlation on a given image with a kernel(without using filter2d function).

I am trying to find a general way of correlating image with kernel( mxm size where m an is odd number) but I can't seem to think of a good algorithm that will work for kernel of all sizes. In case of a boundary issue, we compute correlation for each pixel of image as long as the center of the kernel is on this pixel.

My idea is to first classify the pixels into two types, first one being pixels where simple multiplication with kernel is fine. The problem comes with the second type that is the boundary pixels, the pixels at the edges of the image. I can't seem to find a general way and I seem to end up hard-coding it to compute correlation for these pixels for different sizes of kernel.

Does anyone have any ideas or suggestions for a simpler implementation?

edit retag flag offensive close merge delete

Comments

I think you mean convolution? But you could be right the terms are a little fuzzy. Correlation vs. Convolution You could mirror over the border, or simply not include pixels outside of the image (give them a weight of zero). If you want implementation details, I would suggest looking at the OpenCV source.

Der Luftmensch gravatar imageDer Luftmensch ( 2016-10-13 08:04:25 -0600 )edit

You can use may bephasecorrelate and certainly templatematching

LBerger gravatar imageLBerger ( 2016-10-13 11:34:19 -0600 )edit

Sorry for the late reply, @LBerger I didn't understand exactly how template matching can be used for correlation implementation.

kevgeo gravatar imagekevgeo ( 2016-10-18 11:06:39 -0600 )edit