MATLAB Answers

extract contour points belonging to a certain level set

11 views (last 30 days)
Sparsh Garg
Sparsh Garg on 5 Jul 2021
Answered: KSSV on 5 Jul 2021
contourf(Z) creates a filled contour plot containing the isolines of matrix Z.for my case,I would like to generate lines for all levels.
Moreover according to the documentation:
Contour matrix, returned as two-row matrix. This matrix contains the contour levels (heights) and the coordinates of the vertices at each level. The data is arranged sequentially in n sets of columns for n contour lines:
  • The first column in each set contains the contour level and the number of vertices at that level. The top number is the contour level, and the bottom number is the number of vertices.
  • Subsequent columns in the set are the (x, y) coordinates of the vertices. Each column represents an ordered pair. The top number is the x-coordinate, and the bottom number is the y-coordinate.
So for my image a 71x61 grayscale image,the matrix dimension is 2x2154 .
From this ,let's say I would like to extract all the (x,y) coordinates of the vertices lying at level 40.
for example the first column indicates that there are 5 points at level 40,then 119 points at level 40 and so on .
Any pointers on how to extract this

Answers (1)

KSSV
KSSV on 5 Jul 2021
contour should give you the coordinates of the levels mentioned.
level = 40 ;
[c,h] = contour(X,Y,Z,level) ;

Community Treasure Hunt

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

Start Hunting!

Translated by