The Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: sub-pixel shifting of a matrix
Replies: 14   Last Post: Feb 7, 2013 12:23 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Matt J

Posts: 4,997
Registered: 11/28/09
Re: sub-pixel shifting of a matrix
Posted: Feb 25, 2010 1:54 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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/26292-regular-control-point-interpolation-matrix-with-boundary-conditions


>
> @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 zero-padded 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+1-k,1:end+1-j)=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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.