/// <summary> /// This static method creates an distribution array of values between 0-1 /// from the brightness of the given b/w image. /// </summary> /// <param name="distributionArray">An 2D array of <see cref="Single"/> /// to be filled with the distribution values.</param> /// <param name="channelFilename">The filename with the b/w image.</param> /// <param name="stimulusSize">Contains the real size of the stimulus, /// which can be greater than presentation size in webpages.</param> internal static void CreateDistributionArrayFromBWImage( ref float[,] distributionArray, string channelFilename, Size stimulusSize) { if (!System.IO.File.Exists(channelFilename)) { throw new System.IO.FileNotFoundException(); } Bitmap srcImage = (Bitmap)Image.FromFile(channelFilename); // get image size int width = srcImage.Width; int height = srcImage.Height; // create new image Bitmap dstImage = new Bitmap(stimulusSize.Width, stimulusSize.Height, srcImage.PixelFormat); using (Graphics grfx = Graphics.FromImage(dstImage)) { grfx.InterpolationMode = InterpolationMode.HighQualityBicubic; // necessary setting for proper work with image borders grfx.PixelOffsetMode = PixelOffsetMode.HighQuality; grfx.DrawImage(srcImage, 0, 0, stimulusSize.Width, stimulusSize.Height); } PaletteBitmap output = new PaletteBitmap(dstImage); // for each line for (int y = 0; y < stimulusSize.Height; y++) { // for each pixel for (int x = 0; x < stimulusSize.Width; x++) { distributionArray[x, y] = output.GetPixel(x, y).GetBrightness(); } } }
/// <summary> /// Returns a bitmap with a gradient colored DistributionArray with the given size. /// </summary> /// <param name="heatMapBmp">Bitmap to save the heatmap to.</param> /// <param name="gradientBmp">Bitmap with gradient colors</param> /// <param name="size">new bitmap size</param> /// <param name="distributionArray">fixation distributions array</param> /// <returns>heat map bitmap</returns> internal static Bitmap CreateHeatMap( PaletteBitmap heatMapBmp, PaletteBitmap gradientBmp, Size size, float[,] distributionArray) { // get image size int width = size.Width; int height = size.Height; // for each line for (int y = 0; y < height; y++) { // for each pixel for (int x = 0; x < width; x++) { heatMapBmp.SetPixel(x, y, gradientBmp.GetPixel((int)distributionArray[x, y], 0)); } } return((Bitmap)heatMapBmp.Image.Clone()); }
/// <summary> /// This static method creates a heatmap /// from the brightness of the given b/w image where the colors are /// set using the given gradient colored bitmap. /// </summary> /// <param name="heatMapBmp">A <see cref="PaletteBitmap"/> thats /// contents should be overwritten with new heatmap</param> /// <param name="gradientBmp">A <see cref="PaletteBitmap"/> which is gradient /// colored.</param> /// <param name="size">The <see cref="Size"/> of the heatmap.</param> /// <param name="channelFilename">The filename with the b/w image.</param> /// <returns>A <see cref="Bitmap"/> with the new heat map</returns> internal static Bitmap CreateHeatMapFromBWImage( PaletteBitmap heatMapBmp, PaletteBitmap gradientBmp, Size size, string channelFilename) { // get heat map size int newWidth = size.Width; int newHeight = size.Height; if (!System.IO.File.Exists(channelFilename)) { throw new System.IO.FileNotFoundException(); } // Rescale source image to heat map size. Bitmap srcImage = (Bitmap)Images.GetImageOfFile(channelFilename); Bitmap rescaledSrcImage = Images.RescaleImage(new Size(newWidth, newHeight), srcImage, true); PaletteBitmap output = new PaletteBitmap(rescaledSrcImage); // for each line for (int y = 0; y < newHeight; y++) { // for each pixel for (int x = 0; x < newWidth; x++) { heatMapBmp.SetPixel( x, y, gradientBmp.GetPixel((int)(output.GetPixel(x, y).GetBrightness() * (NUMCOLORS - 1)), 0)); } } return(heatMapBmp.Image); }
/// <summary> /// Populates the drawing colors for all subjects using /// the current gradient. /// </summary> private void AssignGradientToSubjects() { PaletteBitmap palBmp = new PaletteBitmap(this.colorMap); int i = 0; XMLSerializableDictionary<string, ColorizationStyle> newStyles = new XMLSerializableDictionary<string, ColorizationStyle>(); foreach (KeyValuePair<string, ColorizationStyle> kvp in this.colorParams.SubjectStyles) { Color newColor = palBmp.GetPixel(i, 0); Pen newFixationPen = (Pen)this.selectedFixationsPen.Clone(); newFixationPen.Color = newColor; Pen newConnectionPen = (Pen)this.selectedConnectionsPen.Clone(); newConnectionPen.Color = newColor; Font newFont = (Font)this.selectedFont.Clone(); newStyles.Add(kvp.Key, new ColorizationStyle(newFixationPen, newConnectionPen, newFont, newColor)); i++; } this.colorParams.SubjectStyles = newStyles; }
/// <summary> /// Returns a bitmap with a gradient colored DistributionArray with the given size. /// </summary> /// <param name="heatMapBmp">Bitmap to save the heatmap to.</param> /// <param name="gradientBmp">Bitmap with gradient colors</param> /// <param name="size">new bitmap size</param> /// <param name="distributionArray">fixation distributions array</param> /// <returns>heat map bitmap</returns> internal static Bitmap CreateHeatMap( PaletteBitmap heatMapBmp, PaletteBitmap gradientBmp, Size size, float[,] distributionArray) { // get image size int width = size.Width; int height = size.Height; // for each line for (int y = 0; y < height; y++) { // for each pixel for (int x = 0; x < width; x++) { heatMapBmp.SetPixel(x, y, gradientBmp.GetPixel((int)distributionArray[x, y], 0)); } } return (Bitmap)heatMapBmp.Image.Clone(); }
/// <summary> /// This static method creates a heatmap /// from the brightness of the given b/w image where the colors are /// set using the given gradient colored bitmap. /// </summary> /// <param name="heatMapBmp">A <see cref="PaletteBitmap"/> thats /// contents should be overwritten with new heatmap</param> /// <param name="gradientBmp">A <see cref="PaletteBitmap"/> which is gradient /// colored.</param> /// <param name="size">The <see cref="Size"/> of the heatmap.</param> /// <param name="channelFilename">The filename with the b/w image.</param> /// <returns>A <see cref="Bitmap"/> with the new heat map</returns> internal static Bitmap CreateHeatMapFromBWImage( PaletteBitmap heatMapBmp, PaletteBitmap gradientBmp, Size size, string channelFilename) { // get heat map size int newWidth = size.Width; int newHeight = size.Height; if (!System.IO.File.Exists(channelFilename)) { throw new System.IO.FileNotFoundException(); } // Rescale source image to heat map size. Bitmap srcImage = (Bitmap)Images.GetImageOfFile(channelFilename); Bitmap rescaledSrcImage = Images.RescaleImage(new Size(newWidth, newHeight), srcImage, true); PaletteBitmap output = new PaletteBitmap(rescaledSrcImage); // for each line for (int y = 0; y < newHeight; y++) { // for each pixel for (int x = 0; x < newWidth; x++) { heatMapBmp.SetPixel( x, y, gradientBmp.GetPixel((int)(output.GetPixel(x, y).GetBrightness() * (NUMCOLORS - 1)), 0)); } } return heatMapBmp.Image; }
/// <summary> /// This static method creates an distribution array of values between 0-1 /// from the brightness of the given b/w image. /// </summary> /// <param name="distributionArray">An 2D array of <see cref="Single"/> /// to be filled with the distribution values.</param> /// <param name="channelFilename">The filename with the b/w image.</param> /// <param name="stimulusSize">Contains the real size of the stimulus, /// which can be greater than presentation size in webpages.</param> internal static void CreateDistributionArrayFromBWImage( ref float[,] distributionArray, string channelFilename, Size stimulusSize) { if (!System.IO.File.Exists(channelFilename)) { throw new System.IO.FileNotFoundException(); } Bitmap srcImage = (Bitmap)Image.FromFile(channelFilename); // get image size int width = srcImage.Width; int height = srcImage.Height; // create new image Bitmap dstImage = new Bitmap(stimulusSize.Width, stimulusSize.Height, srcImage.PixelFormat); using (Graphics grfx = Graphics.FromImage(dstImage)) { grfx.InterpolationMode = InterpolationMode.HighQualityBicubic; // necessary setting for proper work with image borders grfx.PixelOffsetMode = PixelOffsetMode.HighQuality; grfx.DrawImage(srcImage, 0, 0, stimulusSize.Width, stimulusSize.Height); } PaletteBitmap output = new PaletteBitmap(dstImage); // for each line for (int y = 0; y < stimulusSize.Height; y++) { // for each pixel for (int x = 0; x < stimulusSize.Width; x++) { distributionArray[x, y] = output.GetPixel(x, y).GetBrightness(); } } }