Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: sub-pixel shifting of a matrix Date: Thu, 25 Feb 2010 06:54:05 +0000 (UTC) Organization: Xoran Technologies Lines: 32 Message-ID: <hm56qd$t3c$1@fred.mathworks.com> References: <h8ss9r$jhf$1@fred.mathworks.com> <h8svoe$rkb$1@fred.mathworks.com> <hm3fkm$c2u$1@fred.mathworks.com> <hm53ot$ig8$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1267080845 29804 172.30.248.38 (25 Feb 2010 06:54:05 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 25 Feb 2010 06:54:05 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1440443 Xref: news.mathworks.com comp.soft-sys.matlab:611481 "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.