• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 801
  • Last Modified:

normilise atan2 between 0 and pi

i am doing a gradient diffusion to extract the skeleton:

I am computing the gradient orientation: atan2(Dy,Dx). and i want to normilse it between 0 and pi.
how can i normilise it?? i am not getting good results. i tried mod(direction,pi) but i am not sure if it's the right way to do it.

source code + image test1.png the  *.m files are *.txt and the main file is skeletonize.m(txt)

thank you!
show.zip
0
dadadude
Asked:
dadadude
  • 8
  • 3
2 Solutions
 
ozoCommented:
In what way are your results not good?
could you use atan2(Dy,Dx) for Dy > 0 and atan2(-Dy,-Dx) for Dy < 0
0
 
dadadudeAuthor Commented:
i'll post the images:
the original image is in the zip file. I am extracting the right skeleton of the image. and i can't find the error
res.png
0
 
dadadudeAuthor Commented:
i am NOT extracting*
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
dadadudeAuthor Commented:
it's really confusing i double checked the code with the algorithm i still can't find what i am doing wrong.
0
 
MikeAThonCommented:
Your problem might actually reside in the cmax() function, and might involve issues of operator precedence and left-to-right reading order:
Your code:
function D= cmax(R,V,B)
   
    if abs(R) > abs(V) && abs(R) > abs(B)
        D = R;
    elseif abs(V) > abs(R) && abs(V) > abs(B)
        D = V;
    else
        D = B;
    end
 
Try this instead, with added parentheses:
function D= cmax(R,V,B)
   
    if (abs(R) > abs(V))  && (abs(R) > abs(B))
        D = R;
    elseif (abs(V) > abs(R)) && (abs(V) > abs(B))
        D = V;
    else
        D = B;
    end
0
 
dadadudeAuthor Commented:
hello Mike i modified the code. and i received the same image. in the algorithm they ask that the angle be between [0 and 180]. i don't know if it's this part
i'll post the algorithm picture:
in the SSM:
SS = MAX { abs(Angle(k) - abs( angle(h))}; h ~= k.
where andle(h) and angle(k) are the gradient orientations of the symetric pair of adjacent gradient vectors in a 8-connected neighborhood.
alg.bmp
0
 
MikeAThonCommented:
Sorry that was not more helpful.
Perhaps if you started with a manufactured "toy" image, then it would be easier to trace the source of the error.  For example, maybe the image could be a simple X-shaped cross.
0
 
MikeAThonCommented:
Err ... "Sorry that my post was not more helpful"
0
 
dadadudeAuthor Commented:
That's the result for the image Mike. on the crossing it's normal to have the result. but i don't know for the rest.
res1.png
0
 
dadadudeAuthor Commented:
I still can't explain these results.  if it's the direction of how i am computing the regularization and smoothing of the gradient. it seems that there i a problem in the vertical direction of the gradient Dy. hmmm
0
 
dadadudeAuthor Commented:
modification of the angle:
deltap = zeros(size(I));          
for i = 1:size(Dy,1)
    for j = 1:size(Dy,2)
        if Dy(i,j) < 0
            deltap(i,j) = atan2(-Dy(i,j),Dx(i,j));
        elseif Dy(i,j) > 0
            deltap(i,j) = atan2(Dy(i,j),Dx(i,j));
        end
    end
end
res3.png
0
 
dadadudeAuthor Commented:
interesting suggestions lol let's try python now looooooooooool
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now