PixelsorterClassLib is a .NET class library designed for creating advanced pixel sorting effects. It provides extensive control over the sorting criteria and directions, and it even features on-device machine learning capabilities to automatically generate masks for selective sorting.
Below is a basic example demonstrating how to load an image, auto-generate a mask, sort the pixels by their warmth, and save the result.
using NumSharp;
using PixelsorterClassLib.Core;
using PixelsorterClassLib.Masks;
string inputPath = "input.jpg";
string outputPath = "output.jpg";
// 1. Load the image into an NDArray
NDArray imageData = Image.LoadImage(inputPath);
// 2. Get mask options
MaskOptions<BackgroundMaskOptions> options = new BackgroundMaskOptions(0.5f)
// Simpler using var
// var options = new BackgroundMask(0.5f)
// 3. Generate a binary mask using ML inference
NDArray mask = new BackgroundMask().GetMask(inputPath, options);
// 4. Sort image by warmth, left to right, within the boundaries of the mask
NDArray sortedData = Sorter.SortImage(imageData, SortBy.Warmth(), SortDirections.RowLeftToRight, mask);
// 5. Save the sorted image to disk
Image.SaveImage(sortedData, outputPath);
You can easily supply your own callback function Func<Rgba32, float> or use one of the predefined sorting algorithms in the SortBy static class:
SortBy.Hue()SortBy.Brightness()SortBy.Saturation()SortBy.Lightness()SortBy.Warmth()SortBy.Coolness()You can also fetch all available sorting metrics programmatically using:
var criteria = SortBy.GetAllSortingCriteria();
NumSharp arrays.With the commit 4e8741cf the license of this project changed from MIT to EUPL 1.2
All changes, releases etc. done before this commit stay under the MIT license.
PixelsorterClassLib is a .NET class library designed for creating advanced pixel sorting effects. It provides extensive control over the sorting criteria and directions, and it even features on-device machine learning capabilities to automatically generate masks for selective sorting.
Below is a basic example demonstrating how to load an image, auto-generate a mask, sort the pixels by their warmth, and save the result.
using NumSharp;
using PixelsorterClassLib.Core;
using PixelsorterClassLib.Masks;
string inputPath = "input.jpg";
string outputPath = "output.jpg";
// 1. Load the image into an NDArray
NDArray imageData = Image.LoadImage(inputPath);
// 2. Get mask options
MaskOptions<BackgroundMaskOptions> options = new BackgroundMaskOptions(0.5f)
// Simpler using var
// var options = new BackgroundMask(0.5f)
// 3. Generate a binary mask using ML inference
NDArray mask = new BackgroundMask().GetMask(inputPath, options);
// 4. Sort image by warmth, left to right, within the boundaries of the mask
NDArray sortedData = Sorter.SortImage(imageData, SortBy.Warmth(), SortDirections.RowLeftToRight, mask);
// 5. Save the sorted image to disk
Image.SaveImage(sortedData, outputPath);
You can easily supply your own callback function Func<Rgba32, float> or use one of the predefined sorting algorithms in the SortBy static class:
SortBy.Hue()SortBy.Brightness()SortBy.Saturation()SortBy.Lightness()SortBy.Warmth()SortBy.Coolness()You can also fetch all available sorting metrics programmatically using:
var criteria = SortBy.GetAllSortingCriteria();
NumSharp arrays.With the commit 4e8741cf the license of this project changed from MIT to EUPL 1.2
All changes, releases etc. done before this commit stay under the MIT license.