Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Matt J
Posts:
4,997
Registered:
11/28/09


Re: subpixel shifting of a matrix
Posted:
Feb 25, 2010 1:54 AM


"Rajesh " <rv_acharya@rediffmail.com> wrote in message <hm53ot$ig8$1@fred.mathworks.com>... > interp2 works well alright (thanks shalin mehta) but it fills the shifted region of the matrix with NaNs. =================
You can extrapolate with zeros or any other desired value using the EXTRAPVAL option.
>may be it can be padded by copying the adjacent columns or rows, as the case may be, using 'padarray' function. ====================
That's an option if you have the image processing toolbox. If you don't have it, you can create a convolution matrix modified for replicate extrapolation using my interpMatrix tool:
http://www.mathworks.com/matlabcentral/fileexchange/26292regularcontrolpointinterpolationmatrixwithboundaryconditions
> > @Mat > does conv2 work for fractions >1?? but even this, i guess, leaves the shifted column (for shift in x direction) in shambles.
I don't know what you mean by leaving the column in shambles.
For shifts >1, you could just convolve using a zeropadded version of the convolution kernel. However, it would probably be more efficient to do an integer shift of the image first, which just requires that you reorder the image data, and do a fractional shift using the method I've described. circshift() will work for the integer shift, but I've found circshift to be slower than as compared to just reordering the data manually, as in
Result=zeros(size(Image)); Result(1:end+1k,1:end+1j)=Image(k:end,j:end);
Incidentally, I've just noticed that interp2 has a "*METHOD" option allowing you to tell it that the samples are uniformly spaced, for more optimized execution. This probably means that interp2 will implement the interpolation as a separable convolution for you under the hood.
> I need to shift an image by say 6.3 pixels in x direction in such a way that as if only the object in the image has moved and the background is retained as it is. ==============
If the object is completely surrounded by background values of zero, I don't see what's challenging about that. What I've outlined above will work.



