octave saves the data of a contour in the contourc format which is a little bit special for me.
Is there some function or script which translates these data into a sequence of point coordinates which I can plot then? For one level only!
Thanks
Example to process contourc format for one level (with potentially more than one contours at that level).
A = zeros(5); A(2:4,2:4) = 1; A(3,3) = 0; % example image
ContourCFormat = contourc(A, 1); % one level only (but here happens to have two contours)
C = cell();
while ~isempty(ContourCFormat)
N = ContourCFormat(2,1);
C{end+1} = ContourCFormat(:, 2 : 1+N);
ContourCFormat(:, 1 : 1+N) = []; % Remove processed points
end
C =
{
[1,1] =
1.5000 2.0000 3.0000 4.0000 4.5000 4.5000 4.5000 4.0000 3.0000 2.0000 1.5000 1.5000 1.5000
2.0000 1.5000 1.5000 1.5000 2.0000 3.0000 4.0000 4.5000 4.5000 4.5000 4.0000 3.0000 2.0000
[1,2] =
2.5000 3.0000 3.5000 3.0000 2.5000
3.0000 2.5000 3.0000 3.5000 3.0000
}
Explanation: From the octave manual:
The return value is a 2xn matrix containing the contour lines in the following format:
[lev1, x1, x2, …, levn, x1, x2, ... len1, y1, y2, …, lenn, y1, y2, …]in which contour line n has a level (height) of
levnand length oflenn.
Therefore for the first contour, we collect columns from 2 to N+1, where N is given by element (2,1) of the contourc output. Then we delete N+1 elements and process the next contour in the same way, until there are no more points left.