예제 #1
0
/*!
  \ingroup group_imgproc_retinex

  Enhance the contrast of a color image using the Retinex technique, based on the Retinex ImageJ plugin:
  Retinex filtering is based on Land's theory of image perception, proposed to explain the perceived colour constancy
  of objects under varying illumination conditions. Several approaches exist to implement the retinex principles,
  among these the multiscale retinex with colour restoration algorithm (MSRCR) combines colour constancy
  with local contrast enhancement so images are rendered similarly to how human vision is believed to operate.
  This method is based on the Retinex ImageJ plugin written by Francisco Jiménez Hernández, which is a
  modified implementation of the Retinex filter from the GIMP package by Fabien Pelisson.

  \param I : The color image after application of the Retinex technique.
  \param scale : Specifies the depth of the retinex effect.
  \param scaleDiv : Specifies the number of iterations of the multiscale filter.
  Values larger than 2 exploit the "multiscale" nature of the algorithm.
  \param level : Specifies distribution of the Gaussian blurring kernel sizes for Scale division values > 2:
    - 0, tends to treat all image intensities similarly,
    - 1, enhances dark regions of the image,
    - 2, enhances the bright regions of the image.
  \param dynamic : Adjusts the color of the result. Large values produce less saturated images.
  \param kernelSize : Kernel size for the gaussian blur operation. If -1, the kernel size is calculated from the image size.
*/
void vp::retinex(vpImage<vpRGBa> &I, const int scale, const int scaleDiv,
    const int level, const double dynamic, const int kernelSize) {
  //Assert scaleDiv
  if(scaleDiv < 1 || scaleDiv > 8) {
    std::cerr << "Scale division must be between the interval [1 - 8]" << std::endl;
    return;
  }

  if(scale < 0) {
    std::cerr << "Scale must be positive !" << std::endl;
    return;
  }

  if(I.getWidth()*I.getHeight() == 0) {
    return;
  }

  MSRCR(I, scale, scaleDiv, level, dynamic, kernelSize);
}
예제 #2
0
/*
 * Applies the algorithm
 */
static void
retinex (GimpDrawable *drawable,
         GimpPreview  *preview)
{
  gint          x, y, width, height;
  gint          size, bytes;
  guchar       *src  = NULL;
  guchar       *psrc = NULL;
  GimpPixelRgn  dst_rgn, src_rgn;

  bytes = drawable->bpp;

  /*
   * Get the size of the current image or its selection.
   */
  if (preview)
    {
      src = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
                                          &width, &height, &bytes);
    }
  else
    {
      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
                                          &x, &y, &width, &height))
        return;

      /* Allocate memory */
      size = width * height * bytes;
      src = g_try_malloc (sizeof (guchar) * size);

      if (src == NULL)
        {
          g_warning ("Failed to allocate memory");
          return;
        }

      memset (src, 0, sizeof (guchar) * size);

      /* Fill allocated memory with pixel data */
      gimp_pixel_rgn_init (&src_rgn, drawable,
                           x, y, width, height,
                           FALSE, FALSE);
      gimp_pixel_rgn_get_rect (&src_rgn, src, x, y, width, height);
    }

  /*
    Algorithm for Multi-scale Retinex with color Restoration (MSRCR).
   */
  psrc = src;
  MSRCR (psrc, width, height, bytes, preview != NULL);

  if (preview)
    {
      gimp_preview_draw_buffer (preview, psrc, width * bytes);
    }
  else
    {
      gimp_pixel_rgn_init (&dst_rgn, drawable,
                           x, y, width, height,
                           TRUE, TRUE);
      gimp_pixel_rgn_set_rect (&dst_rgn, psrc, x, y, width, height);

      gimp_progress_update (1.0);

      gimp_drawable_flush (drawable);
      gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
      gimp_drawable_update (drawable->drawable_id, x, y, width, height);
    }

  g_free (src);
}
예제 #3
0
파일: methode.cpp 프로젝트: drewdru/imager
void process( unsigned char * dImage, int nWidth, int nHeight, size_t n, int mode)
{
    rvals.scales_mode = mode;
    MSRCR( dImage, nWidth, nHeight, 3);
}