필터 지우기
필터 지우기

I have x and y values, but, how can I draw the shape?

조회 수: 3 (최근 30일)
med-sweng
med-sweng 2013년 12월 19일
댓글: Image Analyst 2018년 7월 26일
I have the following x and y values:
149.5000 75.5000 451.5000 279.5000
which denote (respectively):
x-min y-min x-max y-max
Having those dimensions, how can I draw them as a shape that will represent the boundary with the above values?
Thanks.
  댓글 수: 5
med-sweng
med-sweng 2013년 12월 19일
편집: med-sweng 2013년 12월 19일
@José-Luis. If "convexhull()" draws a convex, yes, that would do. How can we draw it using the dimensions above? Can it also be filled with a colour? Thanks
Image Analyst
Image Analyst 2013년 12월 19일
With a convex hull, if the shape were a "E" shape, you'd get a rectangle. The convex hull is like if you stretched a rubber band around all of your vertices. It's the shape of the rubber band. All of the concave parts would get "filled in."

댓글을 달려면 로그인하십시오.

답변 (2개)

José-Luis
José-Luis 2013년 12월 19일
편집: José-Luis 2013년 12월 19일
doc convhull
nVal = 50;
xx = 149.5 + rand(nVal,1).*(451.5-149.5);
yy = 75.5 + rand(nVal,1).*(279.5-75.5);
k = convhull(xx,yy);
plot(xx(k),yy(k),'r-',xx,yy,'b+')
doc patch if you want a filled polygon.
  댓글 수: 10
Image Analyst
Image Analyst 2013년 12월 20일
편집: Image Analyst 2013년 12월 20일
convhull is not mandatory. The original poster merely said that he had corners of the bounding box of some shape and he wanted to plot it. No convex hull is necessary. Moreover, even if the shape inside the bounding box was weird, say a star shape or irregular blob shape, and say you wanted to plot that, then there is no reason to call convhull. For example, look at this code that draws a soft star. No convhull is called. And med-swing didn't ask for convhull he just said he wanted to know how to plot the bounding box defined by a vector where the x and y were all in the same vector.
% Demo macro to draw a rounded star (like a splat).
%
clc;
close all;
clear all;
workspace;
% Select the inner and outer radius.
outerRadius = 44 % You can change this
innerRadius = 19 % You can change this
% Select the number of lobes around the circle.
numberOfLobes = 8; % You can change this
period = 2 * pi / numberOfLobes;
meanRadius = (outerRadius + innerRadius)/2
amplitude = (outerRadius - innerRadius)/2
t = (0:.005:1)*2*pi; % Independent parameter.
variableRadius = amplitude * cos(2*pi*t/period) + meanRadius
subplot(2,2,1);
plot(variableRadius);
ylim([0 outerRadius]);
title('VariableRadius');
period = 2*pi; % Need to change this now.
x2 = variableRadius .* cos(2*pi*t/period);
y2 = variableRadius .* sin(2*pi*t/period);
subplot(2,2,2);
plot(t, x2);
title('x2 vs. t');
subplot(2,2,3);
plot(t, y2);
title('y2 vs. t');
subplot(2,2,4);
plot(x2,y2,'b')
title('x2 vs y2');
% Maximize window.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Image Analysis Demo','numbertitle','off')
I think José-Luis may have misunderstood the question when med-sweng asked how to draw "a shape that will represent the boundary with the above values" - he had the shape already - an x min and max, and a y min and max. He was not asking how to find a different shape of the bounding shape. If he had , then a convex hull might have been a good suggestion (or a call to regionprops), but he already has the bounding box, given by that array, and just needed to know how to plot it.
Youssef  Khmou
Youssef Khmou 2013년 12월 20일
he did not specify the shape so there is an infinity, you first gave the first shape ; a rectangle, then José gave a deformed rectangle using rand. The idea is clear now .

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2013년 12월 19일
Try this:
m = [149.5000 75.5000 451.5000 279.5000]
x1 = m(1);
x2 = m(3);
y1 = m(2);
y2 = m(4);
x = [x1 x2 x2 x1 x1];
y = [y1 y1 y2 y2 y1];
plot(x, y, 'r', 'LineWidth', 3);
grid on;
  댓글 수: 7
Ramesh Bala
Ramesh Bala 2018년 7월 26일
also could you say how can one draw an ellipse with the major axis coords without knowing the minor axis values?
Image Analyst
Image Analyst 2018년 7월 26일
Not sure what this means exactly. Try reading the FAQ: https://matlab.wikia.com/wiki/FAQ#How_do_I_create_an_ellipse.3F

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by