着上篇往下讲,与White Patch Retinex同样。Gray-World 也是恢复图像原色的算法。两种算法最核心的不同在于对光源强度的预计。

Gray World 算法基于一个如果The Gray World Assumption:on average, the world is gray.也就是说自然图像的像素颜色平均值为常值1/2(在颜色范围归一化在[0,1]的情况下)。

以下讲述该算法的详细数学推导过程。

算法:

(1)基本算法

下式是图像成像的数学表达,详细的含义在上篇文章Color Constancy 色彩恒常性(1)White Patch Retinex中有讲到。这里就不再反复。



依旧如果像素的色彩和像素的亮度值成比例

依照Gray World如果,对取平均。则有



且 

式中E(R) = 1/2即是由Gray World如果得出。带入后得到:

依旧如果E(G)=1。那么光源的强度能够预计为:

   (1)

终于经过色彩恢复后的图像为:

(2)

(2)改进算法

上述的原始算法具有非常大的局限性。若图像的颜色比較单一,那么就不再满足gray world如果。为解决问题,提出了一些改进的算法,当中的一种主要思路是,先对图像进行切割。然后求切割后每块图像的颜色均值,进而求出总的颜色均值。用数学能够表示为下式:

式中。nr为切割后区域的个数,a(Rj)为第j个区域的平均像素值。

通过这样的方法求得终于的ai带入式(1)中。

在这样的思想下,提出了一种详细的算法,该算法求三个通道的直方图,然后将其量化为10类,那么终于能够将256*256*256中颜色量化为10*10*10=1000种颜色。书中将这1000种类描写叙述为1000 buckets。

(直观的理解就是把整幅图像画一个直方图,该直方图有1000个柱,也就是1000个bucket)。

终于的求ai的式子为:

式中,nnz为直方图中像素点个数非0的bucket的个数,nb为bucket的总个数(依照书中的意思。nb =1000,我的理解是nb = nnz),ci(j)为第j个bucket中像素的值。

相同的。将求得的ai带入式(1)中。然后带入式(2)求得恢复后的输出。

MATLAB代码:

代码(当中,para=0是原始的方法,para=1是改进后的方法):

  1. function out = GrayWorld(in,para)%
  2. %%%% copyright: ofalling %%%%
  3. if( nargin < 2 )
  4. para = 0;
  5. end
  6. out = zeros(size(in));
  7. inDouble = double(in)/255;
  8. % % gamma correction
  9. gamma = 1/2.2;
  10. inDouble = inDouble.^(gamma);
  11. if ( para == 0)% 最原始的gray world算法
  12. for i = 1:3
  13. a(i) = mean(mean(inDouble(:,:,i)));
  14. f = 2;% f = 2/E(G),assume E(G)=1
  15. out(:,:,i) = inDouble(:,:,i)/(f*a(i));
  16. end
  17. elseif( para == 1)% 先使用直方图切割为1000块再计算光源强度
  18. inR = inDouble(:,:,1);
  19. inG = inDouble(:,:,2);
  20. inB = inDouble(:,:,3);
  21. nb = 0;
  22. for r = 1:10
  23. for g = 1:10
  24. for b = 1:10
  25. bucket = find((inR>0.1*(r-1))&(inR<0.1*r)&(inG>0.1*(g-1))&...
  26. (inG<0.1*g)&(inB>0.1*(b-1))&(inB<0.1*b));
  27. if (size(bucket)~=0 )
  28. nb = nb+1;
  29. bucketC(nb,:) = [0.1*r-0.05 0.1*g-0.05 0.1*b-0.05];
  30. end
  31. end
  32. end
  33. end
  34. for i =1:3
  35. a(i) = mean(bucketC(:,i));
  36. f = 2;% f = 2/E(G),assume E(G)=1
  37. out(:,:,i) = inDouble(:,:,i)/(f*a(i));
  38. end
  39. end

(1)原始算法结果



(2)改进算法结果



对照实验(1)和(2)的结果,发现改进后的算法明显比原始的算法效果好。且改进后的算法使用范围更广。

The Gray World Assumption的更多相关文章

  1. ISP算法高水平分析(上)

    ISP算法高水平分析(上) 一.ISP基本框架及算法介绍 ISP是Image Signal Processor的缩写,全称是影像处理器.在相机成像的整个环节中,它负责接收感光元件(Sensor)的原始 ...

  2. [LeetCode] Gray Code 格雷码

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  3. 滤镜 filter:gray 变灰色

    .gray { -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); ...

  4. 【LeetCode】Gray Code

    Gray Code The gray code is a binary numeral system where two successive values differ in only one bi ...

  5. Gray Code

    Gray Code The gray code is a binary numeral system where two successive values differ in only one bi ...

  6. 【leetcode】Gray Code (middle)

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  7. [LintCode] Gray Code 格雷码

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  8. 44. Decode Ways && Gray Code

    Decode Ways A message containing letters from A-Z is being encoded to numbers using the following ma ...

  9. LeetCode——Gray Code

    Description: The gray code is a binary numeral system where two successive values differ in only one ...

随机推荐

  1. linux内核情景分析之内核中的互斥操作

    信号量机制: struct sempahore是其结构,定义如下 struct semaphore { atomic_t count;//资源数目 int sleepers;//等待进程数目 wait ...

  2. C#图解教程学习笔记——接口

    一.接口概念接口是指定一组函数成员而不实现它们的引用类型.所以只能类和结构来实现接口. 二.声明接口1. 接口声明不能包含:数据成员.静态成员,只能包含以下类型的非静态成员函数:方法.属性.事件.索引 ...

  3. Codeforces Round #315 (Div. 2)【贪心/重排去掉大于n的元素和替换重复的元素】

    B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. Tallest Cow

    题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a p ...

  5. Vue中this.$router.push参数获取

    传递参数的方法:1.Params 由于动态路由也是传递params的,所以在 this.$router.push() 方法中path不能和params一起使用,否则params将无效.需要用name来 ...

  6. BZOJ 4543 2016北京集训测试赛(二)Problem B: thr 既 长链剖分学习笔记

    Solution 这题的解法很妙啊... 考虑这三个点可能的形态: 令它们的重心为距离到这三个点都相同的节点, 则其中两个点分别在重心的两棵子树中, 且到重心的距离相等; 第三个点可能在重心的一棵不同 ...

  7. OpenSSL使用1(用OpenSSL生成自签名证书在IIS上搭建Https站点)(用于iOS的https访问)

    前提: 先安装openssl,安装有两种方式,第一种直接下载安装包,装上就可运行:第二种可以自己下载源码,自己编译.这里推荐第一种. 安装包:http://slproweb.com/products/ ...

  8. mysql-实现远程连接(授权法)

    远程连接阿里云主机的mysql,遇到以下问题: 1.连接被拒,无法连接 可能原因:1.3306(默认)端口未开放,在控制台设置防火墙规则: 2. host字段的值改为%就表示在任何客户端机器上能以ro ...

  9. 避免在block中循环引用(Retain Cycle in Block)

    让我们长话短说.请参阅如下代码: - (IBAction)didTapUploadButton:(id)sender { NSString *clientID = @"YOUR_CLIENT ...

  10. Start Developing iOS Apps Today

    view types - view常见类型