CPLofcontourc

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - CPL/Closed Polygon Lists
Introduced first in SolidGeometry 3.6, Creation date: 2017-03-17, Last change: 2025-09-14

converts the contourc format into the CPL format

Description

Matlab's contourc function is a powerful function to create contours from image bit maps similar to the marching cube function in 3D. Nevertheless the resulting point list format is outdated. This function converts the contourc format into the CPL format.

See Also: CVLofcontourc , CPLofimage , SGofVMdelaunay , SGofVMmarchcube

Example Illustration

 missing image of CPLofcontourc(C,rem)

Syntax

CPL=CPLofcontourc(C,[rem])

Input Parameter

C: result of the contourc function
rem: removes straight lines if true; default is true

Output Parameter

CPL: Closed polygon list

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

Output

Algorithm Steps

  1. Initialize rem to true. If a second argument is provided and is not empty, set rem to that value.
  2. Transpose the input matrix C to CPL.
  3. Initialize variables k and n to 0 and the number of rows in CPL, respectively.
  4. Initialize i to 1 and ck as a NaN vector of length n.
  5. Iterate over the rows of CPL using a while loop:
  6. Trim ck to the first k-1 elements and set the corresponding rows in CPL to NaN.
  7. Remove the first row of CPL.
  8. If rem is true, call CVLremstraight to remove straight lines from CPL and keep only the first two columns.
  9. 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