"Rajesh " <email@example.com> wrote in message <firstname.lastname@example.org>... > 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:
> > @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
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.