how to find convex hull and the area of intersection
2 views (last 30 days)
Show older comments
Hello,
I want to find the convex hull of this two triangle and then find the intersection area of them.to find convex hull i tried convhull(A,B) but it did not work. Is there anybody to explain how can i use convhull function for the code below.
P(1,:) = [0.9 2.1]; P(2,:) = [2.8 5.2]; P(3,:) = [5.7 2.3];
Q(:,:) = ... [2.7 1.1 5.6 4.1 8.0 1.8];
X = [P(:,1) P(1,1)];
Y = [P(:,2) P(1,2)];
line(X,Y)
A = [Q(:,1)
Q(1,1)];
B = [Q(:,2) Q(1,2)];
line(A,B)
0 Comments
Accepted Answer
Image Analyst
on 23 Dec 2011
Sum the intersection image to find the area. Try this code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
P(1,:) = [0.9 2.1];
P(2,:) = [2.8 5.2];
P(3,:) = [5.7 2.3];
windowSize = 30;
image1 = poly2mask(P(:,1), P(:,2), windowSize, windowSize);
subplot(2, 2,1);
imshow(image1);
title('P', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
Q = [2.7 1.1; 5.6 4.1; 8.0 1.8];
image2 = poly2mask(Q(:,1), Q(:,2), windowSize, windowSize);
subplot(2, 2, 2);
imshow(image2);
title('Q', 'FontSize', fontSize);
intersectionImage = image1 | image2;
subplot(2, 2, 3);
imshow(intersectionImage);
title('Intersection Image', 'FontSize', fontSize);
intersectionCoords = [P;Q];
convexHullIndex = convhull(intersectionCoords)
convexHullImage = poly2mask(intersectionCoords(convexHullIndex,1), intersectionCoords(convexHullIndex,2), windowSize, windowSize);
subplot(2, 2, 4);
imshow(convexHullImage);
title('Convex Hull Image', 'FontSize', fontSize);
2 Comments
Image Analyst
on 23 Dec 2011
If you don't want to do it quantized (via digital arrays/images) then you're going to have to figure it out analytically using formulas for the 6 lines to find intersection points and the overlap area. Maybe the Symbolic Toolbox could help you - I don't know because I don't have that toolbox.
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!