How to group the green contour and the yellow contour?

2 vues (au cours des 30 derniers jours)
cliffy
cliffy le 10 Oct 2018
Commenté : cliffy le 12 Oct 2018
I'm using "imcontour" to get the contour of some image. The resulting image is as follow. Is there any way that I can pick out the green contour together as a group, and the yellow contour together as a group?

Réponse acceptée

jonas
jonas le 10 Oct 2018
Modifié(e) : jonas le 10 Oct 2018
Sure, the first output of the imcontour, just like any other contour plot, is a contour matrix . If you understand its structure, then it's quite easy to extract the individual levels. If you upload the image and code I might give it a try.
Here is another question where I first had to parse the contour matrix.
  5 commentaires
jonas
jonas le 12 Oct 2018
Sure, here is an example. The contours are stored in out and their levels are stored in lvls.
%%Some data
t=1:100;
y=1:100;
z=peaks(100);
%%Get contours
C=contour(t,y,z,'levellist',[2 3]);
cnt=[0];nc=[];idc=[];
while (sum(nc)+cnt)<size(C,2)
cnt=cnt+1;
idc=[idc sum(nc)+cnt];
nc=[nc C(2,idc(end))];
end
%%Save levels and remove the corresponding cols
lvls=C(1,idc);
for j=1:length(idc)-1
out{j} = C(:,idc(j)+1:idc(j+1)-1);
end
cliffy
cliffy le 12 Oct 2018
Thank you for the help! It's a nice idea to store matrix in cell. I got it.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by