How to Normalize co-ordinates to [-sqrt2,sqrt2]?

2 views (last 30 days)
I have got the following code
d = size(img); % dimension
img = double(img);
xstep = 2/(d(1)-1);
ystep = 2/(d(2)-1);
[x,y] = meshgrid(-1:xstep:1,-1:ystep:1);
How does this normalisation actually works? Can any one please help.
  1 Comment
dpb
dpb on 13 Feb 2015
Well, how about trying a sample case at the command line and see?
BIG HINT: What's the value of [1-(1)'?

Sign in to comment.

Accepted Answer

Eduardo Márquez
Eduardo Márquez on 13 Feb 2015
Edited: Eduardo Márquez on 13 Feb 2015
As I see it, this normalizing the domain of the image, not the image, ie, seeks to center the coordinate (0,0).
[ 1:-1, -1:1] as the domain you want, take the d (1) -1 to count 0. If only outside [0:1,0:1] simply to know the step calculated 1 / (d (1) -1), but as it wants to [-1: 1] requires doubling leave half of steps on one side and half on the other. 2 / (d (1) -1), double spaces become large and occupy the range [-1:1].
Then meshgrid generate matrix with you new domain, instead of going to [1:d(1),1:d(2)] was added to the domain [-1:1,-1:1].
Read meshgrid function to know who works.
I hope to help.
Example:
Image is 3x3, then d=[3 3 1];
The image domain is [(1,1) (1,2) (1,3);(2,1) (2,2) (2,3);(3,1) (3,2) (3,3)];
The meshgrid generate the domain [(-1,-1) (-1,0) (-1,1) : (0,-1) (0,0) (0,1) :(1,-1) (1,0) (1,1)];
  3 Comments
Eduardo Márquez
Eduardo Márquez on 13 Feb 2015
Calculates the distance from one point to another, in the example d = [3 3 1];
xstep = 2 / (3-1) = 2/2 = 1, that is, starts at -1 meshgrid adding 1 up to 1, therefore, the new domain are [-1, -1 + 1, -1 + 1 + 1] = [- 1,0,1]
If d = [5 5 1]; xstep = 2 / (5-1) = .5, the new domain [-1, -1 + 0.5, -1 +.5+. 5 ...] = [-1, -.5,0,.5,1];
analogous in ystep
Anushka
Anushka on 13 Feb 2015
Thank you very much sir,it helped me .
can you please explain the following code also
z = clipimg(x+i*y,mask);
function [cimg,cindex,dim] = clipimg(img,mask)
dim = size(img); cindex = find(mask~=0); cimg = img(cindex); return;

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolating Gridded Data in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!