Filter löschen
Filter löschen

how to find convex hull and the area of intersection

1 Ansicht (letzte 30 Tage)
dediydi
dediydi am 22 Dez. 2011
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)

Akzeptierte Antwort

Image Analyst
Image Analyst am 23 Dez. 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 Kommentare
dediydi
dediydi am 23 Dez. 2011
thanks a lot for your attention, but that is not what i really want. i want to see the two triangle,their convex hull and intersection points on the standart output. Maybe we should not use poly2mask function.
Image Analyst
Image Analyst am 23 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by