Sydney-Informatics-Hub / aigis

Tools for aerial and satellite imagery acquisition, processing, annotation, and analysis using artificial intelligence
MIT License
5 stars 1 forks source link

Shape Regularisation Improvement Ideas #5

Open hlydecker opened 7 months ago

hlydecker commented 7 months ago

Thanks to a custom AI persona, I have these suggestions:

Increase Segmentation Resolution: Ensure the initial segmentation model outputs detailed masks by possibly using a higher resolution or adjusting the model to prefer detail over generalization. This might mean retraining the model with different parameters or using a more detailed dataset.

Improve calculate_segment_angles Function: The accuracy of initial angle calculation is crucial. Consider adjusting the maxAngleChange parameter dynamically based on the complexity of building shapes in your dataset. For highly irregular buildings, a lower maxAngleChange might preserve more original details.

Adjust Skew Tolerance: In orthogonalise_polygon, the skewTolerance parameter determines how much deviation from orthogonal lines is acceptable. By fine-tuning this parameter, you can better control the balance between regularization and detail preservation.

Polygon Simplification Pre-Process: Before orthogonalizing, you might want to simplify the polygon with a tolerable margin that removes minor, possibly noisy, deviations but keeps significant shape features. This could be done using shapely's simplify method with a carefully chosen tolerance value.

Review Rotation Strategy: In rotate_polygon, you rotate the polygon based on median deviation angle to align with cardinal directions. This step might induce errors or over-simplifications. Consider if a less aggressive rotation or a differentiated approach based on the building's orientation can yield better results. Maybe use a rotation based on the longest side of the bounding rectangle instead of median angle.

Enhanced Handling of Inner Rings: When you process inner rings (holes within polygons), ensure that their orientation and relation to the outer ring are preserved accurately. This might require more sophisticated logic that recognizes and maintains the spatial relationships between interior and exterior boundaries through the orthogonalization process.

Debugging and Validation: Make sure to include more robust debugging and validation checks throughout the processing. Check for validity using explain_validity at key points to understand if and why a polygon becomes invalid. Also, visualize the transformation steps to gauge where the process might be overly simplifying the shapes.

Post-Process Smoothing: After orthogonalizing, you might end up with shapes that are correct in orientation but still have jagged edges due to the alignment to cardinal points. Smooth these edges, if necessary, while preserving the general orthogonal shape.

Efficiency and Optimizations: Consider the efficiency of your code. If processing a large number of buildings, optimizations in how you handle polygons can significantly impact overall runtime. For example, vectorized operations or parallel processing might speed up the process.

Experiment with Parameters: Given the variability in building shapes, it might be beneficial to experiment with different sets of parameters (maxAngleChange, skewTolerance) for different subsets of your data. This variation can help in identifying the best compromise between regularity and detail preservation for each subset.