Example #1
0
        public PlottableHeatmap(double[,] intensities, Config.ColorMaps.Colormaps colorMap, string label, double[] axisOffsets, double[] axisMultipliers)
        {
            this.width  = intensities.GetUpperBound(1) + 1;
            this.height = intensities.GetUpperBound(0) + 1;
            double[] intensitiesFlattened = Flatten(intensities);
            this.min             = intensitiesFlattened.Min();
            this.max             = intensitiesFlattened.Max();
            this.brush           = new SolidBrush(Color.Black);
            this.pen             = new Pen(brush);
            this.axisOffsets     = axisOffsets;
            this.axisMultipliers = axisMultipliers;
            this.colorMap        = colorMap;
            this.label           = label;


            this.intensitiesNormalized = Normalize(intensitiesFlattened);

            int[] flatARGB = IntensityToColor(this.intensitiesNormalized, colorMap);

            bmp   = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            scale = new Bitmap(1, 256, PixelFormat.Format32bppArgb);

            int[] scaleRGBA = IntensityToColor(Normalize(Enumerable.Range(0, scale.Height).Select(i => (double)i).Reverse().ToArray()), colorMap);

            Rectangle  rect         = new Rectangle(0, 0, bmp.Width, bmp.Height);
            Rectangle  rectScale    = new Rectangle(0, 0, scale.Width, scale.Height);
            BitmapData bmpData      = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat);
            BitmapData scaleBmpData = scale.LockBits(rectScale, ImageLockMode.ReadWrite, scale.PixelFormat);

            Marshal.Copy(flatARGB, 0, bmpData.Scan0, flatARGB.Length);
            Marshal.Copy(scaleRGBA, 0, scaleBmpData.Scan0, scaleRGBA.Length);
            bmp.UnlockBits(bmpData);
            scale.UnlockBits(scaleBmpData);
        }
Example #2
0
        private int[] IntensityToColor(double[] intensities, Config.ColorMaps.Colormaps colorMap)
        {
            switch (colorMap)
            {
            case Config.ColorMaps.Colormaps.grayscale:
                return(new Config.ColorMaps.Grayscale().IntensitiesToARGB(intensities));

            case Config.ColorMaps.Colormaps.grayscaleInverted:
                return(new Config.ColorMaps.GrayscaleInverted().IntensitiesToARGB(intensities));

            case Config.ColorMaps.Colormaps.viridis:
                return(new Config.ColorMaps.Viridis().IntensitiesToARGB(intensities));

            case Config.ColorMaps.Colormaps.magma:
                return(new Config.ColorMaps.Magma().IntensitiesToARGB(intensities));

            case Config.ColorMaps.Colormaps.inferno:
                return(new Config.ColorMaps.Inferno().IntensitiesToARGB(intensities));

            case Config.ColorMaps.Colormaps.plasma:
                return(new Config.ColorMaps.Plasma().IntensitiesToARGB(intensities));

            case Config.ColorMaps.Colormaps.turbo:
                return(new Config.ColorMaps.Turbo().IntensitiesToARGB(intensities));

            default:
                throw new ArgumentException("Colormap not supported");
            }
        }