how is it possible to correspond negative coordinates to matrix indices?

3 views (last 30 days)
I was working on a piece of code which take a cartesian image and change it to polar demonstration (rho , phi).
using "interp2" negative non-integer numbers correspond to indices of an image (which are positive integers).
in part of the code we see:
x = Pixel_spacing* (-(nrad-0.5):(nrad-0.5));
[x,y] = meshgrid(x,x);
polar_image = interp2(x, y, double(image), xi, yi);
here x and y are expanded on something like (-9.5 , 9.5) and through this these negative coordinates work as indices of matrix. note that x ,y and image are the same size.
having this example in mind, how can correspond indices of a matrix to negative and non-integer contents of another matrix, like the function 'interp2' does?
thanks

Answers (1)

chicken vector
chicken vector on 23 Apr 2023
You can normalise the coordiante to transorm them into indeces:
x = -9.5 : 9.5; % -9.5 -8.5 ... 8.5 9.5
xIdx = x - x(1) + 1; % 1 2 ... 19 20

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!