How to group the green contour and the yellow contour?
2 views (last 30 days)
Show older comments
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?

0 Comments
Accepted Answer
jonas
on 10 Oct 2018
Edited: jonas
on 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.
5 Comments
jonas
on 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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!