Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
Euclidean distance transform

Subject: Euclidean distance transform

From: mshahrashoub shahrashoub

Date: 25 Aug, 2010 11:05:06

Message: 1 of 4


I am working on image processing and I have a large dataset.
My question is, I have noisy and non linear vector which contains distance of the samples.

For the linear model, I am using histogram of the vector then i am running it with two pass algorithm. But output is not satasfactory.

Does anybody can help me how can I try it with quadratic model, I tried it with one dimensional squared euclidean distance transform but I think i made a mistakes in some where. I am posting the code, if someone has another idea it would be perfect.

Many thanks.

Quadratic equation is s =(f(p) + p2) − (f(q) + q2) / 2p − 2q
%% one dimensional squared euclidean distance transform
function [d] = euclidean (f )

f % Is my vector
G = size(f,1); % is size of the vector
n = G;


v = ones(n,1);





for q=2:n-1,
     s = (( f(q) + q ^ 2) - ( f(v(k)) + v(k)^2 )) / ( 2 * ( q - v(k)));
        while ( s <= z(k)) && (k>=2)

            s = (( f(q) + q ^ 2) - ( f(v(k)) + v(k)^2 )) / ( 2 * ( q - v(k)));


v(k) = q;

z (k) = s;
z (k+1)= 1;


for q=1:n-2,
    while (z(k+1)<q) && (k<=n-1)
        d(q) = (q-v(k)^2) + f(v(k));

Subject: Euclidean distance transform

From: ImageAnalyst

Date: 25 Aug, 2010 12:08:47

Message: 2 of 4

You're missing some things that will make it easier for people to help
1) Some sample data - the "f" vector that gets sent into this
2) Comments. All good code should have comments. Yours has virtually
3) Version of MATLAB you are using along with what toolboxes. For
example, do you have the Image Processing Toolbox, which has a bwdist
function? The bwdist function does the Euclidean Distance Transform,
along with some other distance transforms such as city block,
chessboard, and quasi-euclidean.
4) Plus I don't even know what "one dimensional squared euclidean
distance transform" or the "quadratic model euclidean distance
transform" is or the difference between them. All I know is the
regular EDT like you'd intuitively think about - you know, the one
that uses the Pythagorean Theorem (BTW, why did Euclid get the eponym
instead of Pythagoras).
5) Not sure what f is. Is it an array of 2D coordinates, like an Nx2
array of (x,y) coordinates? If so, what is "f(p)"? And what does 2p,
p2, and q2 mean? What are those? Are they indexes, or (x,y)
coordinate pairs?
6) A description of the "mistakes" you believe you've made. Do you
have any error messages that were generated, or some output data that
you think is counterintuitive?

Do you have any images that illustrate your problem/mistake/situation
that you can upload to

Subject: Euclidean distance transform

From: mshahrashoub shahrashoub

Date: 25 Aug, 2010 13:41:10

Message: 3 of 4

You are right, sorry , this is the first time that I m posting a message.
Question was not clear.

I am using Matlab 2010a and I have Image processing toolbox.
Let me make the question much more clear

I am working on loopy belief propagation(I am trying to impliment it to the matlab).

I have a vector ex: X

 X = [ 1 2 3 5 9 11 18 22 26] ;

as you can see numbers are not increasing in some manner, to solve this (for linear model) I am using two pass algorithm (similar to sort algorithm )
Example :
L = size(X,2); % Size of the vector
  %Straight forward Pass , checks from left to right
for i=2:L,
   previous = X(i-1) + c ; % add constant value to compare the data fractions
          if prev < X(i) % Compare previous sample with actual sample
                   X(i) = previous ;

%Backward Pass ,it checks from right to left
for i=L-1 :-1:1
    previous = X(i+1) + 1;
            if prev < X(i) % is the value smaller than previous one ?
                  X(i) = previous ;
output = 1 2 3 4 5 6 7 8 9
This is working fine but my problem is , as you can see in above function it requires constant value to compare samples with each other. But i dont want to give the constant value to compare it, because in each iteration my values are changing. Also my data set is extremly noisy. thats why it is not increase or decrease in linear manner.
thats why I want to use quadratic model or another thing. Thanks for spending time.



Subject: Euclidean distance transform

From: mshahrashoub shahrashoub

Date: 25 Aug, 2010 13:53:04

Message: 4 of 4

As a result :)

Does anybody know, how can I increase or decrease this values (see ex:X) respect to the some kind of model ?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us