CPSremovearea

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - CPL/Closed Polygon Lists
Introduced first in SolidGeometry 4.5, Creation date: 2019-02-15, Last change: 2025-09-14

removes CPS/polyshape regions of small area



See Also: CPLremstraightAmin , CPLremovearea , imofimsketch

Example Illustration

 missing image of CPSremovearea(CPS,sline)

Syntax

[CPSN,CPRA]=CPSremovearea(CPS,[sline])

Input Parameter

CPS: Original CPS/polyhsape
sline: minimal length (not area)

Output Parameter

CPSN: remaining polyshapes
CPRA: Removed polyshapes

Examples


I=imofimsketch(imreadlastchanged); CPS=polyshape(CPLofimage(I)); cla; plot(CPS)
CPSremovearea(CPS)




Copyright 2019-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, CPSremovearea, is designed to remove regions of a polyshape (CPS) that have a small area. It is part of the SolidGeometry library and was introduced in version 4.5.

Input Parameters

Output Results

Algorithm Steps

  1. Check if CPS is numeric and convert it to a polyshape if necessary.
  2. Determine if CPS is a structure with a field ps. If so, extract the polyshape and set a flag iscps to true.
  3. Calculate a default minimal area s based on the bounding box of CPS. This is done by dividing the size of the bounding box by 200 and squaring the result.
  4. If sline is provided and greater than zero, update s to be the square of sline.
  5. Extract the regions of the polyshape using PSregions and sort them by area in descending order.
  6. Calculate the area of each region and create a logical array asel to identify regions with an area greater than or equal to s.
  7. Separate the regions into those to be retained (ps) and those to be removed (ra) based on asel.
  8. If iscps is true, update the original CPS structure with the retained regions and their associated properties. Also, create a new CPS structure for the removed regions.
  9. If iscps is false, simply return the retained and removed regions as polyshapes.
  10. If no output arguments are specified, plot the retained regions in green and the removed regions in red using SGfigure, CPSplot, and CPLplot.
Algorithm explaination created using ChatGPT on 2025-08-19 08:18. (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