Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
med-sweng
med-sweng am 19 Dez. 2013
Kommentiert: Image Analyst am 26 Jul. 2018
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 Kommentare
med-sweng
med-sweng am 19 Dez. 2013
Bearbeitet: med-sweng am 19 Dez. 2013
@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 am 19 Dez. 2013
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."

Melden Sie sich an, um zu kommentieren.

Antworten (2)

José-Luis
José-Luis am 19 Dez. 2013
Bearbeitet: José-Luis am 19 Dez. 2013
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 Kommentare
Image Analyst
Image Analyst am 20 Dez. 2013
Bearbeitet: Image Analyst am 20 Dez. 2013
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 am 20 Dez. 2013
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 .

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 19 Dez. 2013
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 Kommentare
Ramesh Bala
Ramesh Bala am 26 Jul. 2018
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 am 26 Jul. 2018
Not sure what this means exactly. Try reading the FAQ: https://matlab.wikia.com/wiki/FAQ#How_do_I_create_an_ellipse.3F

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by