Contour detection implemented with pure C#. Extract outer shapes and holes from textures, and generate precise pixel-aligned boundaries for pixel art. No external dependencies.Image Contours is a pure C# implementation of the Suzuki-Abe border following algorithm for Unity. It analyzes images and extracts both outer contours and inner holes, including their hierarchical relationships.In addition to contour detection, the package provides a way to convert contour pixels into pixel-aligned boundary vertices, which can be useful when working with pixel art or grid-based geometry.This package is intended for developers who need direct access to image shape data for rendering, tooling, or geometry generation.This package focuses onPure C# implementation: No native plugins or platform-specific dependenciesContour hierarchy support: Detects both outer contours and holes, with parent-child relationshipsPixel boundary reconstruction: Convert contour pixels into corner-based boundary verticesConfigurable detection behavior: Supports 4-connected and 8-connected neighborhoodsFlexible foreground definition: Use alpha threshold or provide a custom predicateTypical Use CasesVisualizing outlines of sprites or texturesGenerating boundaries for pixel art assetsBuilding editor tools that operate on image shapesPreparing data for mesh generation or collision approximationExtracting regions for gameplay or AI systemsWhat's IncludedCore contour detection implementationPixel boundary reconstructionExample components for visualization:LineRenderer-based drawingPixel-based drawingSample scene with configurable parametersFull source code with XML documentationNUnit test casesCore FeaturesImplementation of Suzuki-Abe border following algorithmSingle-pass contour detectionDetects both outer contours and holesHierarchical contour structure with parent-child relationshipsConfigurable pixel connectivity (4 or 8)Custom predicate support for foreground detectionBuilt-in alpha threshold detectionMip level support for Texture2DAutomatic coordinate conversion to Unity's Texture2D spaceAPI HighlightsContourDetector.FindContoursOpaque(): Detect contours from fully opaque pixelsContourDetector.FindContoursByAlpha(): Detect contours using an alpha thresholdContourDetector.FindContours(): Detect contours using a custom predicateContour.Pixels: Access ordered contour pixel coordinatesContour.ToPixelBoundary(): Convert contour pixels into pixel-aligned corner verticesContour.BoundingBox: Compute the bounding rectangle of a contourContour.IsHole: Identify whether a contour represents a holeContour.Parent: Access contour hierarchyPixel Boundary FeatureThe ToPixelBoundary() method converts contour pixels into a sequence of vertices that represent the outer boundary of the shape, assuming each pixel is a square.Vertices correspond to pixel corners, not centersOutput forms a continuous loop suitable for rendering or geometry useThis can be helpful when working with pixel art, where contour pixels alone may not be sufficient to describe the visible shape.Sample ComponentsContourLineDrawerDraw contours in scene using Unity's LineRendererSupports pixel-center and pixel-boundary modeContourPixelDrawer:Draw contours directly onto texturesAdjustable colors for outer contours and holesOptional filtering of hole contoursRuntime parameter tweaking in the Unity EditorTestingIncludes NUnit-based unit testsCovers typical scenarios such as:Simple shapesSingle pixelsNested contoursAlso includes tests for edge cases (e.g., empty input)Platform SupportWorks on all Unity platformsNo native plugins, shaders or external dependenciesCode & ExtensibilityWritten in clean, readable C#XML documentation includedSource code is fully accessible and can be modified to fit specific needsNotesThe package operates on binary or thresholded images; input quality may affect resultsFor specialized workflows, customization may be required depending on project requirementsAI assistance was used during development for:Initial code generationDocumentation draftingUnit test generationAll generated content was reviewed and adjusted by the developer.The implementation was checked against the original Suzuki-Abe paper and tested across multiple scenarios.





