7 Haziran 2015 Pazar

Saliency Map for Emgucv

Hi,
        Today. I want to tell about Saliency Map function for Emgu Cv which is written by me. I needed this function one of my projects and i looked for it for long time but i can not find any successful opencv or emgucv function for this method. Finally i decided to write this function. I have been searched it for long time and i found this papers about this method. Especially, 3. source was the main source for me.



  1. http://cs-people.bu.edu/jmzhang/BMS/BMS_iccv13_preprint.pdf
  2. http://www.vision.caltech.edu/~harel/share/gbvs.php
  3. http://mmcheng.net/salobj/


         Saliency Map is an image processing method to filter background and detect foreground objects in the image. It is based on color difference of pixels in the image. Basic algorithms can be explain as;

  1. Take average of the image.
  2.  Find all pixels' difference from average for 3 color appearance parameters
  3.  Find maximum difference
  4. Use it to normalize the results for scale 0 - 255
  5. Create a grayscale image which contains all normalized pixels of first image



Saliency Map Function;

      private Image<Gray, Byte> SaliencyMap(Image<Bgr, Byte> img)
      {
          Image<Hsv, Byte> hsvimage = img.Convert<Hsv, Byte>();

          Hsv means = hsvimage.GetAverage();
          double huemean = means.Hue;
          double satmean = means.Satuation;
          double vmean = means.Value;

          Image<Gray, Byte> saliencymap = img.Convert<Gray, Byte>();
          double maxvalue = 0;

          for (int i = 1; i < hsvimage.Rows; i++)
          {
              for (int j = 1; j < hsvimage.Cols; j++)
              {

                  double sqr1 = (huemean - hsvimage[i, j].Hue) * (huemean - hsvimage[i, j].Hue);
                  double sqr2 = (satmean - hsvimage[i, j].Satuation) * (satmean - hsvimage[i, j].Satuation);
                  double sqr3 = (vmean - hsvimage[i, j].Value) * (vmean - hsvimage[i, j].Value);
                  if (sqr1 + sqr2 + sqr3 > maxvalue)
                  {
                      maxvalue = sqr1 + sqr2 + sqr3;
                  }
                  saliencymap[i, j] = new Gray(sqr1 + sqr2 + sqr3);
              }
          }
          maxvalue = maxvalue / 255;
          for (int i = 1; i < hsvimage.Rows; i++)
          {
              for (int j = 1; j < hsvimage.Cols; j++)
              {

                  double sqr1 = (huemean - hsvimage[i, j].Hue) * (huemean - hsvimage[i, j].Hue);
                  double sqr2 = (satmean - hsvimage[i, j].Satuation) * (satmean - hsvimage[i, j].Satuation);
                  double sqr3 = (vmean - hsvimage[i, j].Value) * (vmean - hsvimage[i, j].Value);

                  saliencymap[i, j] = new Gray((sqr1 + sqr2 + sqr3) / maxvalue);

              }

          }
          return saliencymap;
      }

Hiç yorum yok:

Yorum Gönder