Exemplo n.º 1
0
        ///////////////////////////////////////////////////////////////////////////////
        // Methods for doing main class job                                          //
        ///////////////////////////////////////////////////////////////////////////////
        #region METHODS

        /// <summary>
        /// Initializes non designer fields.
        /// </summary>
        private void InitializeElements()
        {
            Bitmap colorMapBitmap = new Bitmap(AttentionMaps.NUMCOLORS, 1, PixelFormat.Format32bppArgb);

            this.colorMap = new PaletteBitmap(colorMapBitmap);

            this.CreateHeatMapBitmap(new Size(100, 100));
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Creates a newly sized heatmap template to be filled
        ///  with the data
        /// </summary>
        /// <param name="stimulusSize">A <see cref="Size"/> containing the new stimulus size.</param>
        private void CreateHeatMapBitmap(Size stimulusSize)
        {
            if (this.heatMap != null)
            {
                this.heatMap.Dispose();
                this.heatMap = null;
            }

            if (this.heatMap == null ||
                this.heatMap.Width != stimulusSize.Width ||
                this.heatMap.Height != stimulusSize.Height)
            {
                Bitmap heatMapBitmap = new Bitmap(stimulusSize.Width, stimulusSize.Height, PixelFormat.Format32bppArgb);
                this.heatMap = new PaletteBitmap(heatMapBitmap);
                heatMapBitmap.Dispose();
            }
        }
Exemplo n.º 3
0
        /// <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();
                }
            }
        }
Exemplo n.º 4
0
        /// <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());
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
    /// <summary>
    ///  Creates a newly sized heatmap template to be filled 
    ///  with the data
    /// </summary>
    /// <param name="stimulusSize">A <see cref="Size"/> containing the new stimulus size.</param>
    private void CreateHeatMapBitmap(Size stimulusSize)
    {
      if (this.heatMap != null)
      {
        this.heatMap.Dispose();
        this.heatMap = null;
      }

      if (this.heatMap == null ||
        this.heatMap.Width != stimulusSize.Width ||
        this.heatMap.Height != stimulusSize.Height)
      {
        Bitmap heatMapBitmap = new Bitmap(stimulusSize.Width, stimulusSize.Height, PixelFormat.Format32bppArgb);
        this.heatMap = new PaletteBitmap(heatMapBitmap);
        heatMapBitmap.Dispose();
      }
    }
Exemplo n.º 7
0
    ///////////////////////////////////////////////////////////////////////////////
    // Methods for doing main class job                                          //
    ///////////////////////////////////////////////////////////////////////////////
    #region METHODS

    /// <summary>
    /// Initializes non designer fields.
    /// </summary>
    private void InitializeElements()
    {
      Bitmap colorMapBitmap = new Bitmap(AttentionMaps.NUMCOLORS, 1, PixelFormat.Format32bppArgb);
      this.colorMap = new PaletteBitmap(colorMapBitmap);

      this.CreateHeatMapBitmap(new Size(100, 100));
    }
Exemplo n.º 8
0
    /// <summary>
    /// Initializes standard graphic elements.
    /// </summary>
    private void InitializeElements()
    {
      if (Properties.Settings.Default != null)
      {
        Ogama.Properties.Settings set = Properties.Settings.Default;
        this.gazeFixationsPen = new Pen(set.GazeFixationsPenColor, set.GazeFixationsPenWidth);
        this.gazeFixationsPen.DashStyle = set.GazeFixationsPenStyle;
        this.gazeFixationConnectionsPen = new Pen(set.GazeFixationConnectionsPenColor, set.GazeFixationConnectionsPenWidth);
        this.gazeFixationConnectionsPen.DashStyle = set.GazeFixationConnectionsPenStyle;
        this.gazeFixationsFont = (Font)set.GazeFixationsFont.Clone();
        this.gazeFixationsFontColor = set.GazeFixationsFontColor;
        this.gazeConnections = set.GazeConnections;
        this.gazeNumbers = set.GazeNumbers;

        this.mouseFixationsPen = new Pen(set.MouseFixationsPenColor, set.MouseFixationsPenWidth);
        this.mouseFixationsPen.DashStyle = set.MouseFixationsPenStyle;
        this.mouseFixationConnectionsPen = new Pen(set.MouseFixationsPenColor, set.MouseFixationsPenWidth);
        this.mouseFixationConnectionsPen.DashStyle = set.MouseFixationsPenStyle;
        this.mouseFixationsFont = (Font)set.MouseFixationsFont.Clone();
        this.mouseFixationsFontColor = set.MouseFixationsFontColor;
        this.mouseConnections = set.MouseConnections;
        this.mouseNumbers = set.MouseNumbers;
        this.spotlightRegion = new VGRegion(ShapeDrawAction.Fill, this.GrayBrush);
        this.spotlightRegion.Inverted = true;

        this.gazeDrawingMode = (FixationDrawingMode)Enum.Parse(typeof(FixationDrawingMode), set.GazeFixationsDrawingMode);
        this.mouseDrawingMode = (FixationDrawingMode)Enum.Parse(typeof(FixationDrawingMode), set.MouseFixationsDrawingMode);
      }

      Bitmap colorMapBitmap = new Bitmap(AttentionMaps.NUMCOLORS, 1, PixelFormat.Format32bppArgb);

      // Cache the gradient by painting it onto a bitmap
      using (Graphics bitmapGraphics = Graphics.FromImage(colorMapBitmap))
      {
        Rectangle bmpRct = new Rectangle(0, 0, colorMapBitmap.Width, colorMapBitmap.Height);
        AttentionMaps.Rainbow.PaintGradientWithDirectionOverride(
                                     bitmapGraphics,
                                     bmpRct,
                                     LinearGradientMode.Horizontal);
      }

      this.colorMap = new PaletteBitmap(colorMapBitmap);

      this.CreateHeatMapBitmap(new Size(100, 100));
    }
Exemplo n.º 9
0
    /// <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;
    }
Exemplo n.º 10
0
    /// <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();
    }
Exemplo n.º 11
0
    /// <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;
    }
Exemplo n.º 12
0
    /// <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();
        }
      }
    }