我想取一个位置网格,然后计算每个像素的归一化距离。我不知道这是做正确的方式:matlab:归一化距离图
clear all;
im = imread('test1.png'); % read in the image
im = im(:,:,1); %vectorize image
n = size(im,1); % No of grids in the X-Y plane
xp(1:n)=1:1:n; % Y-coordinates of the plane where we are interested
yp(1:n)=1:1:n;% X-coordinates of the plane where we are interested
Y(1:n,1:n)=0; % This array is for 1-d to 2-d conversion of coordinates
X(1:n,1:n)=0;
for i=1:n
Y(i,:)=yp(i); % all y-coordinates value in 2-d form
end
for i=1:n
X(:,i)=xp(i);% all x-coordinates value in 2-d form
end
Z = zeros(size(X)); % Z dimension is appended to 0
pos = [X(:),Y(:),Z(:)]; %position co-ordinates for x y z dimensions
N = size(pos,1); % size of position matrix
v = cell(N,1); %define cell for storage of x-y plane direction vectors
for j = 1:N
for i = 1:N
vecdir(i,:) = pos(i,:) - pos(j,:); %direction of vectors between each point in the x-y plane
dist(i,:) = pdist2(pos(i,:),pos(j,:)); %distance between each point in the x-y plane
norm(i,:) = vecdir(i,:)./(dist(i,:)).^2; %normalised distance between each point in the x-y plane
end
v{j} = vecdir;
d{j} = dist;
r{j} = norm; %store normalised distances into a cell array
end
R = cellfun(@isnan,r,'Un',0);
for ii = 1:length(r)
r{ii}(R{ii}) =0;
end
在那里,如果我拿第一像素的3×3的图像(大小(IM))我得到的标准化距离到所有其它像素(在XYZ位置格式)为:
>> r{1}
ans =
0 0 0
0 1.0000 0
0 0.5000 0
1.0000 0 0
0.5000 0.5000 0
0.2000 0.4000 0
0.5000 0 0
0.4000 0.2000 0
0.2500 0.2500 0
我只是想知道,如果我这样做的正确的方式(在这个阶段不要太费心约效率)
你是什么意思与归一化距离?标准化通常意味着:在0和1之间,但是你最小和最大的参考是什么? – 2012-08-08 12:09:47
嗨Gunther - 是的就是这样。它是网格上两点之间的单位矢量方向,除以这两点之间的距离。在我的情况下,我除以距离的平方。 – brucezepplin 2012-08-08 12:24:48
不,结果是单位矢量,你现在有了真实的距离矢量,所以你想用那个真实距离矢量的2-范数来除。我对吗?也看到我的回答 – 2012-08-08 12:31:42