DieCenterLib 1.0.0

dotnet add package DieCenterLib --version 1.0.0
                    
NuGet\Install-Package DieCenterLib -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DieCenterLib" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DieCenterLib" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DieCenterLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DieCenterLib --version 1.0.0
                    
#r "nuget: DieCenterLib, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DieCenterLib@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DieCenterLib&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DieCenterLib&version=1.0.0
                    
Install as a Cake Tool

DieCenterLib

A lightweight, high-precision die center detection library designed for personal or internal use.

License Platform OpenCV

⚠️ Note: This library is tailored for specific die images that contain an inner seal ring.
It is not intended as a universal die/wafer detection framework.


Table of Contents


Features

  • Automatic or manual ROI selection
  • Gradient-based edge extraction (Scharr filter)
  • Canny edge detection with adaptive behavior
  • Outlier rejection using k-sigma filtering
  • Linear regression for the four die edges
  • Intersection-based corner finding
  • Subpixel die center estimation
  • Residual statistics: RMSE, Std, MaxAbs, R²
  • Optional ROI intensity export to CSV

Supported Scenarios

This library works best when:

✔ The die has a clear rectangular boundary
✔ There is a seal ring (inward dark/bright border)
✔ Lighting is relatively even
✔ Edges are not heavily occluded
✔ Input resolution ≥ 800 × 800 px


How It Works

DieCenterLib extracts die boundaries by analyzing gradient magnitudes within predefined band regions near each side of the ROI:

  1. ROI Selection

    • Auto ROI using contour detection
    • Or manual ROI defined by user
  2. Gray Conversion + Scharr Gradient
    High-accuracy gradient operator for clean edge responses.

  3. Band Extraction (70–80% coverage)
    Each edge is analyzed only in its dedicated band
    → avoids mixing with corners or noise.

  4. Canny Edge Detection
    Detects candidate edge points.

  5. Line Fitting (with Outlier Removal)
    Using OpenCV’s robust fit + k-sigma rejection.

  6. Corner Finding
    Intersection of opposite edges.

  7. Center Calculation
    Intersection of diagonals formed by TL–BR and TR–BL.


Pipeline Overview

            +-------------------+
            |   Input Bitmap    |
            +---------+---------+
                      |
                      v
            +-------------------+
            | ROI Selection     |
            | Auto / Manual     |
            +---------+---------+
                      |
                      v
            +-------------------+
            | Gray + Scharr     |
            | Gradient (Gx, Gy) |
            +---------+---------+
                      |
                      v
            +-------------------+
            | Region Separation |
            | (Top/Bottom/...)  |
            +---------+---------+
                      |
                      v
            +-------------------+
            |  Canny Edges      |
            +---------+---------+
                      |
                      v
            +-------------------+
            |  Extract Points   |
            |  (per side)       |
            +---------+---------+
                      |
                      v
            +-------------------+
            | Line Fitting      |
            | + Residual Stats  |
            +---------+---------+
                      |
                      v
            +-------------------+
            | Corner Detection  |
            +---------+---------+
                      |
                      v
            +-------------------+
            | Center Position   |
            +-------------------+

Installation

Install-Package DieCenterLib

Dependencies / Prerequisites

DieCenterLib does not include OpenCvSharp4 binaries.
Before using this library, please install the following NuGet packages into your project:

  • OpenCvSharp4 (tested with 4.11.0.20250507)
  • OpenCvSharp4.runtime.win (same version as OpenCvSharp4)
  • OpenCvSharp4.Extensions (same version as OpenCvSharp4)

Example (Package Manager Console):

Install-Package OpenCvSharp4 -Version 4.11.0.20250507
Install-Package OpenCvSharp4.runtime.win -Version 4.11.0.20250507
Install-Package OpenCvSharp4.Extensions -Version 4.11.0.20250507

Basic Usage

using DieCenterLib;

var parameters = new DieCenterParameters
{
    UseAutoRoi = true,
    RoiWidth = 480,
    RoiHeight = 480,
    Coverage = 0.8f,
    BandWidth = 50,
    MinGrad = 5.0f,
    KSigma = 2.0,
};

var result = DieCenterDetector.Run(bitmap, parameters);

// Die center in original image coordinates
var center = result.CenterInImage;

Console.WriteLine($"Center X={center.X}, Y={center.Y}");
Console.WriteLine(result.SummaryText);

API Summary

DieCenterParameters

Property Description
UseAutoRoi Auto ROI by contour detection
ManualRoi / RoiOnImage Manual ROI mode
RoiWidth / RoiHeight Cropping size
Coverage % of ROI width/height used
BandWidth Edge band thickness
MinGrad Minimum gradient magnitude
KSigma Outlier rejection (k-sigma)
CannyLow / CannyHigh Canny thresholds
ExportIntensityCsv Export grayscale CSV
IntensityCsvPath Output CSV path

Troubleshooting

Problem: Edges missing

  • Increase BandWidth
  • Increase MinGrad
  • Ensure ROI is correct

Problem: Weak contrast

  • Apply CLAHE
  • Increase exposure
  • Increase Canny thresholds

Problem: Bad line fitting

  • Increase KSigma
  • Check extracted points

Problem: Auto ROI incorrect

  • Switch to ManualRoi

✔ Stable illumination
✔ Visible seal ring
✔ Moderate contrast
✔ No large scratches
✔ 800×800 px or higher resolution


License

  • MIT License © 2025 Napat Sutikant
  • Uses OpenCvSharp (Apache 2.0).

Acknowledgements

  • OpenCvSharp4 by shimat
  • OpenCV Community
Product Compatible and additional computed target framework versions.
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 246 11/26/2025

Initial public release.