All Projects → ar1st0crat → SciColorMaps

ar1st0crat / SciColorMaps

Licence: MIT license
Custom .NET color maps (user-defined or imported from matplotlib) for scientific visualization

Programming Languages

C#
18002 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to SciColorMaps

Windowscommunitytoolkit
The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building UWP and .NET apps for Windows 10. The toolkit is part of the .NET Foundation.
Stars: ✭ 4,654 (+17800%)
Mutual labels:  uwp, wpf, winforms
Reactiveui
An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
Stars: ✭ 6,709 (+25703.85%)
Mutual labels:  uwp, wpf, winforms
Microsoft.toolkit.win32
This repository contains all controls for WPF and WinForms to simplify and demonstrate usage of UWP controls
Stars: ✭ 257 (+888.46%)
Mutual labels:  uwp, wpf, winforms
DebounceMonitoring
📑 Add debounce logic for any method in a single line.
Stars: ✭ 44 (+69.23%)
Mutual labels:  uwp, wpf, winforms
Microsoft.Toolkit.Win32
This repository contains all controls for WPF and WinForms to simplify and demonstrate usage of UWP controls
Stars: ✭ 345 (+1226.92%)
Mutual labels:  uwp, wpf, winforms
XamlIslands
Repository with several XAML Islands v1 samples (Win32, WPF, and WinForms) to demonstrate how to use it.
Stars: ✭ 47 (+80.77%)
Mutual labels:  uwp, wpf, winforms
Live Charts
Simple, flexible, interactive & powerful charts, maps and gauges for .Net
Stars: ✭ 5,045 (+19303.85%)
Mutual labels:  uwp, wpf, winforms
AsteroidsWasm
Collection of applications based on a single C# .NET Standard project running in: Blazor Client (WebAssembly), Blazor Server, Electron, WPF, WinForms, Xamarin
Stars: ✭ 136 (+423.08%)
Mutual labels:  uwp, wpf, winforms
EBind
🔵 .NET Data Binding we deserve: concise, fast, feature-rich
Stars: ✭ 141 (+442.31%)
Mutual labels:  uwp, wpf, winforms
Reactivemvvm
Cross-platform ReactiveUI sample app built for a talk at MSK .NET conf.
Stars: ✭ 94 (+261.54%)
Mutual labels:  uwp, wpf, winforms
Csla
A home for your business logic in any .NET application.
Stars: ✭ 865 (+3226.92%)
Mutual labels:  uwp, wpf, winforms
Mvvmcross
The .NET MVVM framework for cross-platform solutions, including Xamarin.iOS, Xamarin.Android, Windows and Mac.
Stars: ✭ 3,594 (+13723.08%)
Mutual labels:  nuget, uwp, wpf
DevOpsExamples
A repo to show you how to use a private NuGet feed, such as Telerik, to restore packages in Azure DevOps, GitHub Actions, GitLab CI and AppCenter.
Stars: ✭ 16 (-38.46%)
Mutual labels:  nuget, uwp, wpf
WindowsCommunityToolkit
The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building UWP and .NET apps for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
Stars: ✭ 4,934 (+18876.92%)
Mutual labels:  uwp, wpf, winforms
IconPacks.Browser
The Browser for all available Icon packages from MahApps.Metro.IconPacks
Stars: ✭ 74 (+184.62%)
Mutual labels:  uwp, wpf
Krypton-Toolkit-Suite-Extended-NET-5.470
An extension to the Krypton Toolkit suite of controls for .NET framework 4.7
Stars: ✭ 51 (+96.15%)
Mutual labels:  nuget, winforms
MQTTnet
MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
Stars: ✭ 3,309 (+12626.92%)
Mutual labels:  nuget, uwp
BilibiliLiveRecordDownLoader
Bilibili 直播录制与回放下载
Stars: ✭ 422 (+1523.08%)
Mutual labels:  nuget, wpf
TheLastTime
C# .NET 5 Blazor WebAssembly Progressive Web Application that tracks when was the last time you did something
Stars: ✭ 23 (-11.54%)
Mutual labels:  wpf, winforms
TrialMaker.Demo
A powerful yet straight-forward library suite that provides secure trial license generation and copy-protection features for .NET applications. It also supports premium license generation for expired free-trials.
Stars: ✭ 21 (-19.23%)
Mutual labels:  wpf, winforms

SciColorMaps

License: MIT NuGet

Simple and convenient library providing custom .NET color maps (user-defined or imported from matplotlib) for scientific visualization.

Library comes in two versions (also available as NuGet packages):

  • SciColorMaps.Portable.dll does not rely on any framework-dependent color structure (like System.Drawing.Color or System.Windows.Media.Color). It operates with pure byte arrays, so it can be used in any .NET project.

  • SciColorMaps.dll provides some additional functions that handle GDI+ colors, so it can be used in WinForms and WPF projects.

NuGet packages contain binaries with all 75 matplotlib colormaps included. In most cases only a small subset of them is what is really needed. Luckily, SciColorMaps can be customized and recompiled quite easily. This repo includes special helper script for making your own SciColorMaps dll. Please read instructions here how to use it.

Base ColorMap class

Usage example:

// create 'viridis' colormap with 256 colors, mapping values from range [0, 1]
var cmap1 = new ColorMap();

// create 'rainbow' colormap with 256 colors, mapping values from range [0, 1]
var cmap2 = new ColorMap("rainbow");

// create 'gnuplot' colormap with 256 colors, mapping values from range [-7.5, 7.5]
var cmap3 = new ColorMap("gnuplot", -7.5, 7.5);

// create 'coolwarm' colormap with 64 colors, mapping values from range [10, 100]
var cmap = new ColorMap("coolwarm", 10, 100, 64);

// get color corresponding to value 25
var color = cmap[25];

// print names of all available predefined palettes
foreach (var palette in ColorMap.Palettes)
{
    Console.WriteLine(palette);
}

// prints full set of 75 matplotlib colormaps:
// accent
// afmhot
// autumn
// ...
// ylorbr
// ylorrd

pic1

pic2

User-defined colormaps

Users can create their own color palettes, like this:

// === works for both versions of SciColorMaps ===

var rgbs = new [] { 
                    new byte[] {0, 0, 0},
                    new byte[] {192, 0, 0},
                    new byte[] {255, 224, 255}
                  };
var positions = new float[] { 0, 0.4f, 1 };

// 1) static factory method with default colormap parameters:
var cmap1 = ColorMap.CreateFromColors(rgbs, positions);

// 2) static factory method, full set of parameters:
var cmap2 = ColorMap.CreateFromColors(rgbs, positions, 10, 100, 32);

// 3) ColorMap constructor:
var cmap3 = new ColorMap("my_own_colormap", -2, 2, 128, rgbs, positions);


// === won't compile for SciColorMaps.Portable ===

var colors = new Color[] { Color.Black, Color.Blue, Color.White };

// 4) static factory method with default colormap parameters:
var cmap4 = ColorMap.CreateFromColors(colors, positions);

// 5) static factory method, full set of parameters:
var cmap5 = ColorMap.CreateFromColors(colors, positions, 10, 100, 32);

// 6) ColorMap constructor:
var cmap6 = new ColorMap("fancy_colormap", 10, 100, 32, colors, positions);

Options 3 and 6 allow user setting the name of the custom colormap. Otherwise the name is set by default: "user".

Note also, the first color position should be 0.0f and last position should be 1.0f (otherwise an ArgumentException will be thrown).

Byte arrays can be easily converted to any framework-specific color structures/classes.

For example, in WPF the following extension method can be used:

using SciColorMaps.Portable;

public static class ColorUtils
{
    public static Color ToMediaColor(this byte[] rgb)
    {
        return Color.FromRgb(rgb[0], rgb[1], rgb[2]);
    }
}

...

var cmap = new ColorMap("ocean");
var color = cmap[0.3].ToMediaColor();

User-defined

Grayscale colormaps

SciColorMaps provides the GrayColorMap decorator class. This class replaces base palette with its grayscale analog during construction.

Usage example:

// upper sreenshot
var cmap1 = new GrayColorMap(new ColorMap("gnuplot2", min, max));

// lower screenshot
var cmap2 = new GrayColorMap(new ColorMap("gnuplot2", min, max), GrayScaleOptions.Lightness);


// the three simple algorithms for conversion are implemented
// (as in GIMP: https://docs.gimp.org/2.6/en/gimp-tool-desaturate.html)

// public enum GrayScaleOptions
// {
//     Luminosity,      // gray = 0.21*R + 0.72*G + 0.07*B
//     Lightness,       // gray = (max(R, G, B) + min(R, G, B)) / 2
//     Average          // gray = (R + G + B) / 3
// }

// GrayScaleOptions.Luminosity is used by default

Grayscale

Mirrored colormaps

SciColorMaps also provides the MirrorColorMap decorator class. This class replaces base palette with its mirrored analog during construction.

Usage example:

// mirrored colors
var cmap = new MirrorColorMap(new ColorMap("ocean"));

WinForms demo app

Left button click on surface 2d area -> change colormap to its mirrored version.

Right button click on surface 2d area -> change colormap to its grayscale version.

Left button click on colormap strip -> open dialog for constructing your own palette.

WPF demo app

Shows how to use SciColorMaps.Portable.

WPF

UWP demo app

Shows how to use SciColorMaps.Portable in UWP projects.

The app allows loading sound from wav/mp3/mp4 files as well as recording sound from any input device (most likely, the microphone). When the audio signal is loaded, the app evaluates and visualizes its spectrogram in 2D and 3D. The visualization is based on the colormap selected in the left panel of a main page. Check it out: 3D-spectrogram with 'blues' colormap looks just like mountains in the fog ))

UWP

Compiling SciColorMaps

All customizable parameters are contained in Palette.cs file. So there's a helper script that can generate this file according to particular needs. Here's how to use it:

  1. Download or clone this repo

  2. Go to matplotlib folder and edit colormaps.txt text file, e.g.:

ocean
hot
coolwarm

Basically you include here only colormaps you really need. You can view all available colormap names in colormaps subfolder. If you specify non-existing colormap it'll be simply ignored.

Note also that 'viridis' will be included to the list anyway since it's the default modern colormap.

  1. run generate_cs.py script:
python generate_cs.py [-r 16] [-p] [-a]

-r - colormap resolution (number of base colors; should be 8, 16, 32, 64, 128 or 256)

-p - if specified then generate cs file for portable SciColorMaps version

-a - if specified then generate cs file with all palettes found in colormaps folder (ignoring colormaps.txt input file)

Examples:

// generate cs file with all palettes found in colormaps folder 
// (ignore colormaps.txt) and resolution = 8 base colors

python generate_cs.py -r 8 -a


// generate cs file for portable version 
// (with default resolution = 16 base colors)

python generate_cs.py -p
  1. go to cs subfolder and copy generated Palette.cs file to SciColorMaps or SciColorMaps.Portable project folder.

  2. open SciColorMaps.sln in Visual Studio and compile new dll.

RECTANGULAR conditional compilation symbol

Accessing elements in jagged arrays is significantly faster (up to 40%) compared to rectangular arrays, hence the jagged arrays are used and compiled by default. If an efficient memory management is of more importance then compile SciColorMaps with the 'RECTANGULAR' conditional compilation symbol.

compilation dll size
default ~95kb
RECTANGULAR ~29kb

Also, if you are worried about the memory usage, please note that palette arrays are instantiated lazily in the calling code, e.g.:

var palette = Palette.GnuPlot.Value;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].