How can I grab the contour lines into a new figure ?

I am using contour function to get the contour lines from an image. Now I'd pretend to get only the contour lines created before to make a new image.
I am using [C,h]=contour(a,[0 0]); I have C - ContourMatrix and h - handler.
How can I create a new image (only contour lines) with this C and h ??
Thanks in Advance Mike

 采纳的回答

Easiest way: download contourcs, which will parse the C matrix for you.
a = peaks;
C = contourcs(a, [0 0]);
xy = {C.X; C.Y};
plot(xy{:});

9 个评论

yeah, that's what I need :)
but I have much different contour lines from contourcs compared to contour function. :/
any clue ?
Oops my bad, its the same contour with a few transformations, rotations and shape.
Is there a way to get the contour lines fixed on a same image size ?
You shouldn't need any transformations... assuming you pass identical input to both contour and contourcs, the output contours should be identical. Perhaps if you give some example data and describe how you're trying to display the results, we can figure out what's going on.
these are the two images contours: http://oi39.tinypic.com/2wnbbsm.jpg
left side is using contour function;
right side is using contourcs function;
-------------------------------
function [C,C1]=showCurveAndPhi(I, phi, i)
imshow(I,'initialmagnification',200,'displayrange',[0 255]); hold on;
[C] = contourcs(phi, [0 0]);
[C1]=contour(phi, [0 0], 'g','LineWidth',2);
hold off; title([num2str(i) ' Iterations']); drawnow;
-----------------
The first image is plotted in "real time" using the above function to make the contour and I am plotting C from contourcs() like you told me before:
-----------------
xy = {C.X; C.Y};
figure; plot(xy{:});
------------------
why the contour lines are so different ?
Thanks in advance
Mike
http://oi39.tinypic.com/2wnbbsm.jpg this image seems like just need to flip the contours lines.
but if by some reason the contour lines was like this image http://oi44.tinypic.com/fktmqd.jpg I have the contour but with different image size.
Thanks again ;)
The values of the two plots are the same; they're just being displayed slightly differently. The imshow function is designed for images, so automatically sets the aspect ratio of the axis to 1:1; plot doesn't do this. Setting the 'xlim', 'ylim', and 'dataaspectratio' properties of the two axes to match each other should get the results you want, I think. Here's an example:
I = imread('coins.png');
level = graythresh(I);
BW = im2bw(I,level);
C = contourcs(double(BW), [0 0]);
xy = {C.X; C.Y};
ax(1) = subplot(2,1,1);
imshow(BW);
ax(2) = subplot(2,1,2);
plot(xy{:}, 'b');
props = get(ax(1), {'xlim', 'ylim', 'dataaspectratio'});
set(ax(2), {'xlim', 'ylim', 'dataaspectratio'}, props);
http://oi44.tinypic.com/5d3wc5.jpg and about the turn of the contour lines? because the contour lines is upsidedown, compared to original coins and BW.
thanks a lot (:
Oops, forgot that one... imshow also flips the axis. Add 'ydir' to the list of properties to copy.

请先登录,再进行评论。

更多回答(1 个)

Try checking out ContourMatrix.
"ContourMatrix is also a read-only contourgroup property that you can obtain from the returned handle." -- matlab docs

1 个评论

you mean I should rearrange my C variable from contour function to get the new image ?
thanks

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by