GaussianFit.Core
1.1.0
dotnet add package GaussianFit.Core --version 1.1.0
NuGet\Install-Package GaussianFit.Core -Version 1.1.0
<PackageReference Include="GaussianFit.Core" Version="1.1.0" />
<PackageVersion Include="GaussianFit.Core" Version="1.1.0" />
<PackageReference Include="GaussianFit.Core" />
paket add GaussianFit.Core --version 1.1.0
#r "nuget: GaussianFit.Core, 1.1.0"
#:package GaussianFit.Core@1.1.0
#addin nuget:?package=GaussianFit.Core&version=1.1.0
#tool nuget:?package=GaussianFit.Core&version=1.1.0
GaussianFit.Core
A small .NET Standard 2.0 library for 2D Gaussian fitting from System.Drawing.Bitmap inputs.
Designed for laser / beam profile analysis, with optional ROI-based fitting while preserving
original image coordinates.
Works on .NET Framework 4.6.1+ and modern .NET (6/7/8).
🚀 Install
dotnet add package GaussianFit.Core
💻 Quick Start (Full Image)
using GaussianFit.Core;
var result = GaussianFitter.Run("beam.png", new FitOptions {
Mode = PrepMode.EdgeMean_BorderPct,
BorderPercent = 10,
CutoffPercent = 30,
MaxIterations = 200
});
Console.WriteLine(result.ReportText);
Example output:
A (amplitude) = 215.63
x0, y0 = 123.4, 98.5
σx, σy = 12.1, 11.9
RMSE = 0.024
nRMSE (RMSE/A) = 1.12 % [Excellent]
✂️ Quick Start (With ROI)
You can limit the fitting area using a Region of Interest (ROI) while still obtaining the beam center in original image coordinates.
using GaussianFit.Core;
var roi = new RoiRect(x: 202, y: 163, w: 750, h: 750);
var result = GaussianFitter.Run("beam.png", roi, new FitOptions {
Mode = PrepMode.EdgeMean_BorderPct,
BorderPercent = 10,
CutoffPercent = 30,
MaxIterations = 200
});
// Center in ORIGINAL image coordinates
Console.WriteLine($"Center (orig): x={result.X0:F2}, y={result.Y0:F2}");
Internally:
- The image is cropped to the ROI for fitting
- The fit is performed in local (crop) coordinates
- The final
(x0, y0)is automatically converted back to the original image coordinate system
This avoids edge-light contamination while keeping coordinates consistent.
⚙️ Configuration Options
| Property | Description | Default |
|---|---|---|
Mode |
Preprocessing mode (EdgeMean_BorderPct or Percentile_GlobalP) |
EdgeMean_BorderPct |
BorderPercent |
Border area (%) used for background mean | 10.0 |
PercentileP |
Percentile threshold (0.1–50.0%) for Percentile_GlobalP mode |
10.0 |
CutoffPercent |
Minimum intensity (%) for fitting samples | 30.0 |
MaxIterations |
Maximum Levenberg–Marquardt iterations | 200 |
Epsilon |
Stop criterion ( ΔSSE / SSE) | 1e-9 |
📈 Algorithm Overview
The 2D Gaussian model is defined as:
f(x, y) = A · exp( -((x − x₀)² / (2σₓ²) + (y − y₀)² / (2σᵧ²)) ) + C
where:
| Symbol | Description |
|---|---|
| f(x, y) | Fitted Gaussian intensity value at coordinates (x, y) |
| A | Amplitude (peak value above background) |
| x₀, y₀ | Center position (pixel coordinates) |
| σₓ, σᵧ | Standard deviations (beam spread) |
| C | Constant background offset |
The library minimizes the Sum of Squared Errors (SSE) between the measured data and the model using a Levenberg–Marquardt optimizer.
🎯 Visualization Guide
When drawing overlays (as in the WinForms demo):
- 🟢 Green ellipse = 1σ boundary (~68% energy)
- 🟠 Orange ellipse = FWHM / 2 radius (~1.177σ)
- 🔵 Blue ellipse = 1/e² boundary (radius = 2σ)
Overlay coordinates are provided in ROI-local space when ROI is used, which simplifies drawing on cropped preview images.
🧠 Typical Use Cases
- Laser / optical beam profiling
- Fiber-coupled source alignment
- Spot size and FWHM measurement
- Image-based Gaussian fitting in production or lab environments
📦 Versioning Notes
- v1.1.0
- Added optional ROI-based fitting
- Preserves original image coordinates for
(x0, y0) - Added ROI metadata to
FitResult
📜 License
MIT License © 2025 Napat Sutikant
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Drawing.Common (>= 9.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.