Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8345125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:35:11+00:00 2026-06-09T06:35:11+00:00

I am trying to take a a position grid, and then calculate the normalised

  • 0

I am trying to take a a position grid, and then calculate the normalised distances from each pixel. I’m not sure if this is the right way to do it:

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

where if I take the first pixel in a 3×3 image (size(im)) I get the normalised distances to all other pixels (in x y z position format) as:

>> 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

I just wanted to know if I am doing this the right way (not too bothered about efficiency at this stage)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:35:14+00:00Added an answer on June 9, 2026 at 6:35 am

    Not an answer to the question, but remark about the code:

    the whole initialization of xp, yp, X and Y can be done more easily with meshgrid:

    xp=1:n;
    yp=xp;
    [X,Y]=meshgrid(xp,yp);
    

    Regarding the question itself:

    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
    

    I wouldn’t use ‘norm’ as a variable name as it is also a function

    vecdir is correct; dist also, but essentialy, it should be the same as norm(vecdir(i,:),2) (the function norm(), not your variable!)

    Applying this yiels:

    vecdir(i,:) = pos(i,:) - pos(j,:);
    normvec = vecdir(i,:)./norm(vecdir(i,:),2);
    

    which is imo how you usually normalize a vector. You got the right result, sure, but using pdist2 wasn’t necessary as you already had the distance vector, you only needed to normalize it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to take this content: <div class=content>one,two,three</div> <div class=content>four,five,six</div> <div class=content>seven,eight,nine</div> and .split and
net I am trying to take a value from a previous form typically in
Im trying to attach a picture with and Intent.putExtra, but im not really sure
I'm trying to take four bytes from a binary file and turn them into
I am trying to take ten images, load them into an array, and then
I'm trying to take my Form layout away from tables and entering the world
So I'm basically just trying to take in some file input, and then take
I have a datagridview with 9 columns. I am simply trying take the value
Im trying to take a link either when clicked or hover over be able
While trying to take some arguments for C. I found it really difficult to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.