Be the first to rate this file! 13 Downloads (last 30 days) File Size: 2.17 KB File ID: #35487
image thumbnail

Matrix Convolution with Sub-Pixel Resolution

by

 

Convolve two matrices at sub-pixel resolution, using bilinear interpolation.

| Watch this File

File Information
Description

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.
 
see also: conv2
 
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')

Required Products MATLAB
MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.

Contact us