Retinex算法实现

编程入门 行业动态 更新时间:2024-10-05 03:25:47
本文介绍了Retinex算法实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要实施单尺度视网膜和多尺度视网膜算法在C#, 我搜索了一下,但找不到任何有用的练习项目和代码的艺术品。据我理解正确,我应该:

I need to implement Single Scale retinex and multiscale retinex algorithm in C#, I searched a bit but couldn't find any useful practice projects and artilces with code As I understood correctly I should:

  • 将RGB转换为YUV
  • 使用高斯模糊滤镜模糊图像
  • 使用我'(x,y)= 255 * log10(I(x,y)/ G(x,y))+ 127.5 I - 是照明,G - 高斯核,我' - 结果图片
  • Сonvert返回YUV为RGB
  • Convert RGB to YUV
  • Blur the image using Gaussian blur filter
  • Use I'(x, y) = 255*log10( I(x, y)/G(x, y) ) + 127.5 I - is illumination, G - Gaussian kernel, I' - the result image
  • Сonvert back YUV to RGB
  • 此代码无法正常工作

    public static Image<Bgr, byte> SingleScaleRetinex(this Image<Bgr, byte> img, int gaussianKernelSize, double sigma) { var radius = gaussianKernelSize / 2; var kernelSize = 2 * radius + 1; var ycc = img.Convert<Ycc, byte>(); var sum = 0f; var gaussKernel = new float[kernelSize * kernelSize]; for (int i = -radius, k = 0; i <= radius; i++, k++) { for (int j = -radius; j <= radius; j++) { var val = (float)Math.Exp(-(i * i + j * j) / (sigma * sigma)); gaussKernel[k] = val; sum += val; } } for (int i = 0; i < gaussKernel.Length; i++) gaussKernel[i] /= sum; var gray = new Image<Gray, byte>(ycc.Size); CvInvoke.cvSetImageCOI(ycc, 1); CvInvoke.cvCopy(ycc, gray, IntPtr.Zero); // Размеры изображения var width = img.Width; var height = img.Height; var bmp = gray.Bitmap; var bitmapData = bmp.LockBits(new Rectangle(Point.Empty, gray.Size), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); unsafe { for (var y = 0; y < height; y++) { var row = (byte*)bitmapData.Scan0 + y * bitmapData.Stride; for (var x = 0; x < width; x++) { var color = row + x; float val = 0; for (int i = -radius, k = 0; i <= radius; i++, k++) { var ii = y + i; if (ii < 0) ii = 0; if (ii >= height) ii = height - 1; var row2 = (byte*)bitmapData.Scan0 + ii * bitmapData.Stride; for (int j = -radius; j <= radius; j++) { var jj = x + j; if (jj < 0) jj = 0; if (jj >= width) jj = width - 1; val += *(row2 + jj) * gaussKernel[k]; } } var newColor = 127.5 + 255 * Math.Log(*color / val); if (newColor > 255) newColor = 255; else if (newColor < 0) newColor = 0; *color = (byte)newColor; } } } bmp.UnlockBits(bitmapData); CvInvoke.cvCopy(gray, ycc, IntPtr.Zero); CvInvoke.cvSetImageCOI(ycc, 0); return ycc.Convert<Bgr, byte>(); }

    推荐答案

    看看: www.fer.unizg.hr/ipg/resources/ color_constancy

    这些算法是对Retinex算法的修改(速度提升),尽管作者给了他们有趣的名字:)

    These algorithms are modifications of the Retinex algorithm (with speed improvement) although the author gave them funny names :)

    有一个完整的源代码(C ++,但编写得非常好)。

    There is a full source code (C++, but it is written very nicely).

    更多推荐

    Retinex算法实现

    本文发布于:2023-11-29 02:13:33,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1644888.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:算法   Retinex

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!