GaussianFit.Core 1.1.0

dotnet add package GaussianFit.Core --version 1.1.0
                    
NuGet\Install-Package GaussianFit.Core -Version 1.1.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="GaussianFit.Core" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GaussianFit.Core" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="GaussianFit.Core" />
                    
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 GaussianFit.Core --version 1.1.0
                    
#r "nuget: GaussianFit.Core, 1.1.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 GaussianFit.Core@1.1.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=GaussianFit.Core&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=GaussianFit.Core&version=1.1.0
                    
Install as a Cake Tool

GaussianFit.Core

NuGet License .NET

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

  1. Laser / optical beam profiling
  2. Fiber-coupled source alignment
  3. Spot size and FWHM measurement
  4. 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 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. 
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.1.0 98 1/12/2026
1.0.3 213 11/3/2025
1.0.1 208 10/28/2025