How can I quickly convert contours to polygons? i.e. How can I quickly extract all polygons (x and y) from C, where [C,g] = contour(Z); ?
The structure of C looks complicated -- anyone have something handy?
|
|
0
|
|
|
|
Reply
|
Sujit
|
3/24/2010 7:11:05 PM |
|
"Sujit " <kirpekar@gmail.com> wrote in message <hodo49$t4u$1@fred.mathworks.com>...
> How can I quickly convert contours to polygons? i.e. How can I quickly extract all polygons (x and y) from C, where [C,g] = contour(Z); ?
>
> The structure of C looks complicated -- anyone have something handy?
A = peaks(40);
v=[-10:10]
c = contourc(A, v);
struct = contour2poly(c)
%%
function cstruct = contour2poly(c)
idxlabel = 1;
l = 1;
cstruct = struct('level', {}, 'x', {}, 'y', {});
while idxlabel <= size(c,2)
n = c(2,idxlabel);
cstruct(l).x = c(1,idxlabel+(1:n));
cstruct(l).y = c(2,idxlabel+(1:n));
cstruct(l).level = c(1,idxlabel);
l = l+1;
idxlabel = idxlabel+n+1;
end
end % contour2poly
% Bruno
|
|
0
|
|
|
|
Reply
|
Bruno
|
3/24/2010 7:57:20 PM
|
|
Sujit wrote:
> How can I quickly convert contours to polygons? i.e. How can I quickly
> extract all polygons (x and y) from C, where [C,g] = contour(Z); ?
>
> The structure of C looks complicated -- anyone have something handy?
Take the other approach -- go into the handle that is returned!
polycells = arrayfun( @(ch) horzcat( get(ch,'XData'), get(ch,'YData')),
get(g,'Children'),'Uniform',0); %g is the handle from contour()
will return a cell array, each of which contains an array of coordinate pairs,
X in column 1 and Y in column 2. If that's not exactly how you you would like
the output, you can adjust to suit your needs. Note that the fetched XData and
YData will be column vectors.
|
|
0
|
|
|
|
Reply
|
Walter
|
3/24/2010 8:09:43 PM
|
|
Bruno Luong wrote:
> "Sujit " <kirpekar@gmail.com> wrote in message
> <hodo49$t4u$1@fred.mathworks.com>...
>> How can I quickly convert contours to polygons?
> function cstruct = contour2poly(c)
> while idxlabel <= size(c,2)
Ah, but can you code it without an explicit loop? ;-)
(I have a mental outline for a recursive approach, and a hack in mind that
would use arrayfun...)
|
|
0
|
|
|
|
Reply
|
Walter
|
3/24/2010 8:27:46 PM
|
|
Walter Roberson <roberson@hushmail.com> wrote in message
> Ah, but can you code it without an explicit loop? ;-)
>
> (I have a mental outline for a recursive approach, and a hack in mind that
> would use arrayfun...)
Of course you are right Walter, it is straightforward to convert while-loop to equivalent recursive call:
function cstruct = contour2poly(c)
if isempty(c)
cstruct = struct('level', {}, 'x', {}, 'y', {});
else
n = c(2,1);
idx = 2:n+1;
cstruct = [struct('level', c(1,1), 'x', c(1,idx), 'y', c(2,idx)) ...
contour2poly(c(:,n+2:end))];
end
end % contour2poly
% Bruno
|
|
1
|
|
|
|
Reply
|
Bruno
|
3/24/2010 11:03:07 PM
|
|
"Sujit " <kirpekar@gmail.com> wrote in message
news:hodo49$t4u$1@fred.mathworks.com...
> How can I quickly convert contours to polygons? i.e. How can I quickly
> extract all polygons (x and y) from C, where [C,g] = contour(Z); ?
>
> The structure of C looks complicated -- anyone have something handy?
The structure of the contour matrix isn't that complicated. It's described
in the documentation for CONTOURC:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/contourc.html
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
|
0
|
|
|
|
Reply
|
Steven
|
3/25/2010 2:34:29 AM
|
|
|
5 Replies
351 Views
(page loaded in 0.213 seconds)
Similiar Articles: Contours to polygons - comp.soft-sys.matlabHow can I quickly convert contours to polygons? i.e. How can I quickly extract all polygons (x and y) from C, where [C,g] = contour(Z); ? The struc... shapefile contour plot - comp.soft-sys.matlabContours to polygons - comp.soft-sys.matlab shapefile contour plot - comp.soft-sys.matlab I'm trying to read a shapefile and make a contour plot. numerically integrate over polygon boundary - comp.soft-sys.matlab ...Contours to polygons - comp.soft-sys.matlab Eqn - comp.soft-sys.matlab ..... region using these two known values with 10X10 cell intervals and show as contours ... Finding the normal to a binary contour image - comp.soft-sys ...Contours to polygons - comp.soft-sys.matlab Finding the normal to a binary contour image - comp.soft-sys ... Contours to polygons - comp.soft-sys.matlab image processing ... glpolygonoffset problem - comp.graphics.api.openglContours to polygons - comp.soft-sys.matlab glpolygonoffset problem - comp.graphics.api.opengl... GL_TRIANGLE_STRIP and everything comes out as expected. i.e. glEnable(GL ... Recursive loop - comp.soft-sys.matlabContours to polygons - comp.soft-sys.matlab > function cstruct = contour2poly(c) > while idxlabel <= size(c,2) Ah, but can you code it without an explicit loop? Can mat2cell return a cell array of columns? - comp.soft-sys ...Contours to polygons - comp.soft-sys.matlab... Children'),'Uniform',0); %g is the handle from contour() will return a cell array, each ... Note that the fetched XData and ... Harvard problem - comp.text.texContours to polygons - comp.soft-sys.matlab glpolygonoffset problem - comp.graphics.api.opengl... GL_TRIANGLE_STRIP and ... Contours - DS9 - Harvard University To convert ... Cell Boundary Detection - comp.soft-sys.matlabContours to polygons - comp.soft-sys.matlab... is the handle from contour() will return a cell ... fast edge detection in 3d - comp.graphics.api.opengl - draw ... the ... fast edge detection in 3d - comp.graphics.api.openglto be clearin OpenGL: - draw back facing polygons of your model in wireframe with ... look at the SIGGRAPH 03 and NPAR 04 papers by DeCarlo et al on Suggestive Contours. Contours - DS9 - Harvard UniversityTo convert the contours, select "Convert to Polygons" from the "File" menu of the "Contour Parameters" dialog. The contours are now defined as ds9 polygons, e.g. gw_create_contour_polygons - ET SpatialTechniques - ArcGIS and ...ET GeoWizards for ArcGIS - build topologically correct data sets in ArcMap, Interpolate TIN, Thiessen polygons 7/23/2012 5:04:17 AM
|