Skip to content

Instantly share code, notes, and snippets.

View dg1an3's full-sized avatar
🧩
putting together the pieces

Derek dg1an3

🧩
putting together the pieces
View GitHub Profile
@dg1an3
dg1an3 / Image.csx
Created October 26, 2018 16:12
csx-based image helpers
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
// width/height helpers
static int Width<TPixel>(this TPixel[,] pixels) => pixels.GetLength(0);
static int Height<TPixel>(this TPixel[,] pixels) => pixels.GetLength(1);
// range helper
@dg1an3
dg1an3 / ComplexGeometry.cs
Last active July 3, 2018 19:35
Isocurve Generation via simple marching squares
/// <summary>
///
/// </summary>
public class ComplexGeometry : List<LineSegments>
{
// stores the dictionary
Dictionary<Point, LineSegments> _segments =
new Dictionary<Point, LineSegments>();
/// <summary>
@dg1an3
dg1an3 / MprGenerator.cs
Created July 3, 2018 19:29
Quick and dirty MPR generation from a 3D volume array
public enum Orientation
{
Transverse,
Sagittal,
Coronal
}
public static class MprGenerator<TPixel>
{
// generates an MPR from a volume given an orientation
@dg1an3
dg1an3 / AsciiPixels.fsx
Last active December 20, 2018 20:48
this is a lofi representation of images for experimenting in F#
#load "FsSampleImage.fsx"
open System.Collections.Generic
open FsSampleImage
let rows<'T> (samples: Map<Index,'T>) =
samples // extracts rows of samples from the "image" Map
|> Seq.sortBy (fun samp -> samp.Key.x)
|> Seq.groupBy (fun samp -> samp.Key.y)
|> Seq.map snd
@dg1an3
dg1an3 / histo.cs
Created February 24, 2018 23:35
C# Image Histogram
// for a 2D array of pixels with some pixel type
var pixels = new TPixel[100,100];
// turn into a sequence
var pixelSequence = pixels.Cast<TPixelType>();
// group the sequence and turn to a dictionary, with pixel values as key and bin count as value
var histo = pixelSequence.GroupBy(px => px).ToDictionary(grp => grp.Key, grp => grp.Count());