## Matrix Convolution with Sub-Pixel Resolution

Version 1.0.0.0 (2.17 KB) by
Convolve two matrices at sub-pixel resolution, using bilinear interpolation.

Updated 6 Mar 2012

Tristan Ursell
Sub-pixel Resolved 2D Convolution
March 2012

matout=matoverlay(mat1,mat2,x,y);

This function takes an input matrix mat1 and creates an image of the
matrix mat2 at the position (x,y) in mat1. If (x,y) are floats, then the
image is a sub-pixel bilinear representatoin of mat2 at position (x,y) in
mat1. The output matrix will have the same size at mat1, with no edge effects.

Essentially this is performing a sparse, fully valid convolution of mat2
and mat1 at the point (x,y) with the output size of mat1. The point (x,y)
uses the imaging convention for the coordinate axes.

The values of (x,y) can be floats, as long as they lie within the bounds
of mat1. Combining this function with a for-loop and weights creates a
fully valid 2D subpixel resolution convolution -- see Example -- in
contrast to conv2 which is limited to pixel resolution.

Example:

N=50;
x=1+99*rand(1,N);
y=1+99*rand(1,N);

mat1=zeros(100,100);

mat2=mat2gray(fspecial('gaussian',[11,11],3));

I0=zeros(size(mat1));
ints=rand(1,N);
for i=1:N
I0=I0+ints(i)*matoverlay(mat1,mat2,x(i),y(i));
end

figure;
colormap(hot)
subplot(1,2,1)
imagesc(mat2)
axis equal
axis tight
title('mat2')

subplot(1,2,2)
hold on
imagesc(I0)
plot(x,y,'bo')
axis equal
axis tight
title('Sparse Convolution of mat1 and mat2')

### Cite As

Tristan Ursell (2023). Matrix Convolution with Sub-Pixel Resolution (https://www.mathworks.com/matlabcentral/fileexchange/35487-matrix-convolution-with-sub-pixel-resolution), MATLAB Central File Exchange. Retrieved .

##### MATLAB Release Compatibility
Created with R2009b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux