Syntax
CPL=CPLofcontourc(C,[rem])
Input Parameter
C : | | result of the contourc function |
rem : | | removes straight lines if true; default is true |
Output Parameter
Examples
figure; axis off; text(0.5,0.5,'This is a Test', 'FontSize',36)
I=getframe(gcf); I=flipud(I.cdata(:,:,1)); C=contourc(double(I),1);
CPLofcontourc(C)
Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, CPLofcontourc
, converts the output of MATLAB's contourc
function into a Closed Polygon List (CPL) format. The contourc
function generates contours from image bitmaps, but its output format is considered outdated. This function updates the format to CPL.
Input Parameters
- C: The result of the
contourc
function, which is a matrix containing contour lines.
- rem (optional): A boolean parameter that, if true, removes straight lines from the contour. The default value is true.
Output
- CPL: A matrix representing the Closed Polygon List.
Algorithm Steps
- Initialize
rem
to true. If a second argument is provided and is not empty, set rem
to that value.
- Transpose the input matrix
C
to CPL
.
- Initialize variables
k
and n
to 0 and the number of rows in CPL
, respectively.
- Initialize
i
to 1 and ck
as a NaN vector of length n
.
- Iterate over the rows of
CPL
using a while loop:
- Increment
i
by the number of points in the current contour plus one.
- Increment
k
and store the current index i
in ck
.
- Trim
ck
to the first k-1
elements and set the corresponding rows in CPL
to NaN.
- Remove the first row of
CPL
.
- If
rem
is true, call CVLremstraight
to remove straight lines from CPL
and keep only the first two columns.
- If no output is requested, plot the resulting CPL using
CVLplot
.
Algorithm explaination created using ChatGPT on 2025-08-19 07:13. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21