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

조회 수: 5 (최근 30일)
Anushka
Anushka 2015년 2월 13일
댓글: Anushka 2015년 2월 13일
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