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

 채택된 답변

Kelly Kearney
Kelly Kearney 2013년 6월 7일
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
Uni
Uni 2013년 6월 10일
편집: Uni 2013년 6월 10일
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);
Uni
Uni 2013년 6월 11일
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.
Uni
Uni 2013년 6월 12일
Many many thanks :D

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Angus
Angus 2013년 6월 7일

0 개 추천

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에 대해 자세히 알아보기

태그

질문:

Uni
2013년 6월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by