How can I write matlab program for the following sample region selection from image?
Afficher commentaires plus anciens
I have a point V. I have created some imaginary rays (r1,r2,r3,.....rn) from that point. How can I select two neighboring regions (like A1 and A2) on either side of the ith ray. How can I get the points of that region and the points on the ith ray? Please see the picture: In the picture r1...r3 are imaginary rays created from point V. now I need the region A1 and A2 and points on the ith ray (e.g. r2 ray) N.B. Angle between each ray is equal.

)
2 commentaires
marcel.kaszap@kin.ulaval.ca
le 22 Juin 2016
what about building a function that you can call whenever you need to know if a point P stands inside the wanted areas.
%
% You know V and you know the point P that you want to know if it
% stands close to R2 (between R1 and R3)
%
% Output inside = 0 means that P is on R2
% -1 you are outside of the areas A1 and A2
% 1 you are inside the areas
%
function inside =tellMeWhereAmI(Vx, Vy, Px, Py, angleR2, deltaAngle)
% what is the angle between V and P, here atan2 works between +/-Pi
angle =atan2(Py-Vy, Px-Vx);
% to avoid confusion around +/-Pi
if angle < 0
angle = 2*pi+angle;
end
if angleR2 < 0
angleR2 = 2*pi+angleR2;
end
% to avoid confusion around 0/2Pi
if angle <= angleR2+deltaAngle-2*pi
angle = angle+2*pi;
end
% now we compare
if angle == angleR2
inside = 0; % we are on the line
elseif (angle > angleR2+deltaAngle) | (angle < angleR2-deltaAngle)
inside = -1; % we are outside of the areas
else
inside = 1; % we are inside of the areas
end
end
Do you think it could do the job?
MEK
K M Ibrahim Khalilullah
le 23 Juin 2016
Réponses (1)
marcel.kaszap@kin.ulaval.ca
le 22 Juin 2016
Sorry I have forgotten a little correction, here is the final
%
% You know V and you know the point P that you want to know if it
% stands close to R2 (between R1 and R3)
%
% Output inside = 0 means that P is on R2
% -1 you are outside of the areas A1 and A2
% 1 you are inside the areas
%
function inside =tellMeWhereAmI(Vx, Vy, Px, Py, angleR2, deltaAngle)
% what is the angle between V and P, here atan2 works between +/-Pi
angle =atan2(Py-Vy, Px-Vx);
% to avoid confusion around +/-Pi
if angle < 0
angle = 2*pi+angle;
end
if angleR2 < 0
angleR2 = 2*pi+angleR2;
end
% to avoid confusion around 0/2Pi
if angle <= angleR2+deltaAngle-2*pi
angle = angle+2*pi;
elseif angle-2*pi > angleR2-deltaAngle % I had forgotten this!!!
angle = angle-2*pi;
end
% now we compare
if angle == angleR2
inside = 0; % we are on the line
elseif (angle > angleR2+deltaAngle) | (angle < angleR2-deltaAngle)
inside = -1; % we are outside of the areas
else
inside = 1; % we are inside of the areas
end
end
Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!