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
- CPS: The original polyshape or CPS object. If it is numeric, it is converted to a polyshape without simplification.
- sline: An optional parameter that specifies the minimal length, not area, for the regions to be retained. If not provided, a default value is calculated based on the bounding box of the CPS.
Output Results
- CPSN: The remaining polyshapes after small areas have been removed.
- CPRA: The polyshapes that were removed due to their small area.
Algorithm Steps
- Check if
CPS
is numeric and convert it to a polyshape if necessary.
- Determine if
CPS
is a structure with a field ps
. If so, extract the polyshape and set a flag iscps
to true.
- 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.
- If
sline
is provided and greater than zero, update s
to be the square of sline
.
- Extract the regions of the polyshape using
PSregions
and sort them by area in descending order.
- Calculate the area of each region and create a logical array
asel
to identify regions with an area greater than or equal to s
.
- Separate the regions into those to be retained (
ps
) and those to be removed (ra
) based on asel
.
- 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.
- If
iscps
is false, simply return the retained and removed regions as polyshapes.
- 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