If a point in an image lies inside the sector of the circle or not?

1 view (last 30 days)
I have divided the concerned image into 12 equal sections. My task is to find out points of each section and then mark them. I have written a code which is working fine for some images but not for others. I am not able to find out the reason. Here is the code,
cent = regionprops(croppedImage,'Centroid');
cent = cat(1,cent.Centroid);
figure;
imshow(croppedImage)
hold on;
plot(cent(1,1),cent(1,2),'r*')
contoor = edge(croppedImage,'sobel');
[ril,cil] = find(contoor == 1);
contoor_w = [ril,cil];
contoor_s = size(contoor);
a = linspace(0, 2*pi, 13);
a_s = size(a');
contoor_s = size(contoor);
r = round(((contoor_s(1,1)/2 + contoor_s(1,2)/2)/2)+6);
x = cent(1,1) + r*cos(a);
y = cent(1,2) + r*sin(a);
figure;
imshow(contoor);
hold on;
plot(x,y)
for k = 1:x_s(1,2)-1
P1 = [cent(1,1), cent(1,2)];
P2 = [x(1,k),y(1,k)];
P3 = [x(1,k+1), y(1,k+1)];
P12 = P1-P2;
P23 = P2-P3;
P31 = P3-P1;
s = det([P1-P2;P3-P1]);
contoor_w_s = size(contoor_w);
important = zeros(contoor_w_s(1,1),2);
for i = 1:contoor_w_s(1,1)
P = [contoor_w(i,1), contoor_w(i,2)];
if (s*det([P3-P;P2-P3])>=0 & s*det([P1-P;P3-P1])>=0 & s*det([P2-P;P1-P2])>=0)
important(i,:) = P;
end
end
figure;
imshow(contoor)
hold on;
plot(important(:,2),important(:,1),'g*')
end
This is the "croppedImage" in the code. For this image, results are not coming. Results for each iteration in "k' loop are given as:
Second one is also the "croppedImage" in the code. For this image, the code is working properly. Results for each iteration in "k' loop are given as:
I also tried checking the condition of sum of areas instead of determinant but all same and could not find out the reason. All this I have done using the help from similar questions posted on this platform but I am not able to solve this problem in particular.
If anybody can find out the reason why the code is not working on first picture and what is the solution to solve it, then it will be really helpful.

Accepted Answer

PRACHI SHARMA
PRACHI SHARMA on 22 Nov 2017
I have found out the solution for it. The line of the above code
P = [contoor_w(i,1), contoor_w(i,2)];
should be
P = [contoor_w(i,2), contoor_w(i,1)];

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!