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

4 次查看(过去 30 天)
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 个评论
dpb
dpb 2015-2-13
Well, how about trying a sample case at the command line and see?
BIG HINT: What's the value of [1-(1)'?

请先登录,再进行评论。

采纳的回答

Eduardo Márquez
Eduardo Márquez 2015-2-13
编辑:Eduardo Márquez 2015-2-13
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 个评论
Eduardo Márquez
Eduardo Márquez 2015-2-13
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 2015-2-13
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;

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by