Retinex系列之McCann99 Retinex 分类: 图像处理 Matlab 2014-12-03 11:27 585人阅读 评论(0) 收藏
一、McCann99 Retinex
McCann99利用金字塔模型建立对图像的多分辨率描述,自顶向下逐层迭代,提高增强效率。对输入图像的长宽有
严格的限制,要求可表示成 ,且 
,
。
上述限制来源于金字塔模型的结构要求,由于要对输入图像进行下采样,金字塔中上层低分辨率图像的宽分别为下
层高分辨率图像的1/2,顶层(第n层)大小为,底层(第0层)为原图像。金字塔结构如下图所示。
McCann99算法对输入图像的尺寸要求过于严格,以至于大部分图像不能直接用此算法进行增强,后续有很多改进
措施,此处暂不考虑。
算法从顶层开始,将每个像素与其8领域像素比较,估计每个像素点的亮度值(lightness),比较的迭代次数nIterator
由用户决定,每次迭代有四步操作:比例(ratio)、乘积(product)、重置(reset)、平均(average)。随着迭代次数的增
大,像素受到邻域的影响范围就会扩大。每层计算结束后对该层所得图像进行插值运算,使其尺寸与下一层相同,并
将插值结果作为下一层处理的初始值。对下一层进行相同操作,这样自顶向下直至金字塔底层得到最终增强结果。
对每金字塔每一层:设OP为上一步迭代的乘积;NP为当前迭代的乘积;IP为中间乘积结果;R为该层输入图像;符号
*表示重置操作。其中对于每个像素执行的四步操作使用和Frankle-McCann相同的公式:
变量初始化:
金字塔层数由原始图像尺寸决定,大小为 ,层数为n+1;
OP初始尺寸为,各像素值一般设为原始图像中的最大值;
R:第k层输入图为像原始图像的下采样,大小为;
迭代次数nIterator一般设为4;
图像金字塔模型
二、Matlab实现
function Test()
ImOriginal=imread('fig5.tif');
[m,n,z] = size(ImOriginal);
ImOut = zeros(m,n,z);
for i = 1:z
ImChannel = log(double(ImOriginal(:,:,i))+eps);
ImOut(:,:,i)=retinex_mccann99(ImChannel,4);
ImOut(:,:,i)=exp(ImOut(:,:,i));
a=min(min(ImOut(:,:,i)));
b=max(max(ImOut(:,:,i)));
ImOut(:,:,i)=((ImOut(:,:,i)-a)/(b-a))*255;
end
ImOut=uint8(ImOut);
figure(1);
imshow(ImOriginal);
figure(2);
imshow(ImOut); function Retinex = retinex_mccann99(L, nIterations)
% INPUT: L - logarithmic single-channel intensity image to be processed
% nIterations - number of Retinex iterations
%
% OUTPUT: Retinex - raw Retinex output
global OPE RRE Maximum
[nrows ncols] = size(L); % get size of the input image
nLayers = ComputeLayers(nrows, ncols); % compute the number of pyramid layers
nrows = nrows/(2^nLayers); % size of image to process for layer 0
ncols = ncols/(2^nLayers);
if (nrows*ncols > 25) % not processing images of area > 25
error('invalid image size.') % at first layer
end
Maximum = max(L(:)); % maximum color value in the image
OP = Maximum*ones([nrows ncols]); % initialize Old Product
for layer = 0:nLayers
RR = ImageDownResolution(L, 2^(nLayers-layer)); % reduce input to required layer size
OPE = [zeros(nrows,1) OP zeros(nrows,1)]; % pad OP with additional columns
OPE = [zeros(1,ncols+2); OPE; zeros(1,ncols+2)]; % and rows
RRE = [RR(:,1) RR RR(:,end)]; % pad RR with additional columns
RRE = [RRE(1,:); RRE; RRE(end,:)]; % and rows for iter = 1:nIterations
CompareWithNeighbor(-1, 0); % North
CompareWithNeighbor(-1, 1); % North-East
CompareWithNeighbor(0, 1); % East
CompareWithNeighbor(1, 1); % South-East
CompareWithNeighbor(1, 0); % South
CompareWithNeighbor(1, -1); % South-West
CompareWithNeighbor(0, -1); % West
CompareWithNeighbor(-1, -1); % North-West
end NP = OPE(2:(end-1), 2:(end-1));
OP = NP(:, [fix(1:0.5:ncols) ncols]); %%% these two lines are equivalent with
OP = OP([fix(1:0.5:nrows) nrows], :); %%% OP = imresize(NP, 2) if using Image
nrows = 2*nrows; ncols = 2*ncols; % Processing Toolbox in MATLAB
end
Retinex = NP; %将当前像素与八邻域比较
function CompareWithNeighbor(dif_row, dif_col)
global OPE RRE Maximum
% Ratio-Product operation
IP = OPE(2+dif_row:(end-1+dif_row), 2+dif_col:(end-1+dif_col)) + ...
RRE(2:(end-1),2:(end-1)) - RRE(2+dif_row:(end-1+dif_row), 2+dif_col:(end-1+dif_col));
IP(IP > Maximum) = Maximum; % The Reset step % ignore the results obtained in the rows or columns for which the neighbors are undefined
%因OPE边界处填充了0,故IP对应的边界处结果无意义,直接置成原值
if (dif_col == -1) IP(:,1) = OPE(2:(end-1),2); end
if (dif_col == +1) IP(:,end) = OPE(2:(end-1),end-1); end
if (dif_row == -1) IP(1,:) = OPE(2, 2:(end-1)); end
if (dif_row == +1) IP(end,:) = OPE(end-1, 2:(end-1)); end NP = (OPE(2:(end-1),2:(end-1)) + IP)/2; % The Averaging operation
OPE(2:(end-1), 2:(end-1)) = NP; %power:nrows,ncols的最大公约数且是2的整数次方
function Layers = ComputeLayers(nrows, ncols)
power = 2^fix(log2(gcd(nrows, ncols))); % start from the Greatest Common Divisor
while(power > 1 && ((rem(nrows, power) ~= 0) || (rem(ncols, power) ~= 0)))
power = power/2; % and find the greatest common divisor
end % that is a power of 2
Layers = log2(power); %下采样,将blocksize*blocksize区域映射为一个像素点
function Result = ImageDownResolution(A, blocksize)
[rows, cols] = size(A); % the input matrix A is viewed as
result_rows = rows/blocksize; % a series of square blocks
result_cols = cols/blocksize; % of size = blocksize
Result = zeros([result_rows result_cols]);
for crt_row = 1:result_rows % then each pixel is computed as
for crt_col = 1:result_cols % the average of each such block
Result(crt_row, crt_col) = mean2(A(1+(crt_row-1)*blocksize:crt_row*blocksize, ...
1+(crt_col-1)*blocksize:crt_col*blocksize));
end
end
测试结果:
输入
输出
注:输出时只是简单的进行线性拉伸,使得灰度值落在[0-255],没有使用更好调整方法。
参考:
http://www.cnblogs.com/sleepwalker/p/3676600.html
[1] J.J. McCann, “LessonsLearned from Mondrians Applied to Real Images and Color Gamuts”, Proc.IS&T/SID Seventh Color Imaging Conference, pp. 1-8, 1999.
[2] Brian Funt, FlorianCiurea, and John McCann "Retinex in Matlab," Proceedings of the IS&T/SIDEighth Color Imaging Conference: Color Science, Systems and Applications, 2000.
版权声明:本文为博主原创文章,未经博主允许不得转载。
Retinex系列之McCann99 Retinex 分类: 图像处理 Matlab 2014-12-03 11:27 585人阅读 评论(0) 收藏的更多相关文章
- Matlab调用C程序                                                    分类:            Matlab             c/c++             2015-01-06 19:18    464人阅读    评论(0)    收藏
		Matlab是矩阵语言,如果运算可以用矩阵实现,其运算速度非常快.但若运算中涉及到大量循环,Matlab的速度令人难以忍受的.当必须使用for循环且找不到对应的矩阵运算来等效时,可以将耗时长的函数用C ... 
- 分类算法简介                                                    分类:            B10_计算机基础             2015-03-09 11:08    257人阅读    评论(0)    收藏
		一.决策树 决策树是用于分类和预测的主要技术之一,决策树学习是以实例为基础的归纳学习算法,它着眼于从一组无次序.无规则的实例中 推理出以决策树表示的分类规则.构造决策树的目的是找出属性和类别间的关系, ... 
- Train Problem I                                                       分类:            HDU             2015-06-26 11:27    10人阅读    评论(0)    收藏
		Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ... 
- Makefile    入门与基本语法                                                    分类:            C/C++             ubuntu             2015-05-18 11:16    466人阅读    评论(0)    收藏
		在我看来,学会写简单的Makefile,阅读较复杂的makefile,是每一个Linux程序员都必须拥有的基本素质.Makefile可以自动识别哪些源文件被更改过,需要重新编译,那些不需要.从而节省大 ... 
- Javascript图片预加载详解                                                       分类:            JavaScript             HTML+CSS             2015-05-29 11:01    768人阅读    评论(0)    收藏
		预加载图片是提高用户体验的一个很好方法.图片预先加载到浏览器中,访问者便可顺利地在你的网站上冲浪,并享受到极快的加载速度.这对图片画廊及图片占据很大比例的网站来说十分有利,它保证了图片快速.无缝地发布 ... 
- OC基础:继承.初始化方法,便利构造器                                                    分类:            ios学习 OC             2015-06-16 19:27    84人阅读    评论(0)    收藏
		继承: 1.单向继承,一个类只能有一个父类,一个父类可以有多个子类. 2.单向继承,基类(根类)是OSObject 3.子类可以继承父类的属性和方法 当父类的方法不满足子类的需求时,子类可以重写父类的 ... 
- HIVE快速入门                                                    分类:            B4_HIVE             2015-06-06 11:27    59人阅读    评论(0)    收藏
		(一)简单入门 1.创建一个表 create table if not exists ljh_emp( name string, salary float, gender string) commen ... 
- Gora官方文档之二:Gora对Map-Reduce的支持                                                    分类:            C_OHTERS             2015-01-31 11:27    232人阅读    评论(0)    收藏
		参考官方文档:http://gora.apache.org/current/tutorial.html 项目代码见:https://code.csdn.net/jediael_lu/mygoradem ... 
- javascript中定义事件的三种方式                                                    分类:            C1_HTML/JS/JQUERY             2014-08-07 10:27    634人阅读    评论(0)    收藏
		在javascript中,可以为某个元素指定事件,指定的方式有以下三种: 1.在html中,使用onclick属性 2.在javascript中,使用onclick属性 3.在javascipt中,使 ... 
随机推荐
- maven 的编译插件的配置
			原文: https://stackoverflow.com/questions/29258141/maven-compilation-error-use-source-7-or-higher-to-e ... 
- JAVA数组去除重复数据
			一.用List集合实现 , , , , , , ,}; List<Integer> list = new ArrayList<Integer>(); ; i<str. ... 
- Word 2013安裝字典
			不必從內建的字典中開始,Word 2013 可將您連結到 Office 市集,方便您挑選免費的字典,或從包括多語字典的字典集合中購買. 若要選擇並安裝您想要的字典,請以滑鼠右鍵按一下任何單字,並按一下 ... 
- oracle统计信息
			手工刷ORACLE统计信息 select count(1) from LOG_TRX_DETAIL; select * from user_tab_statistics where table_n ... 
- POJ1195 Mobile phones 【二维树状数组】
			Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14288 Accepted: 6642 De ... 
- leetcode:283. Move Zeroes(Java)解答
			转载请注明出处:z_zhaojun的博客 原文地址:http://blog.csdn.net/u012975705/article/details/50493772 题目地址:https://leet ... 
- 访问某类型的元数据的方式-TypeDescriptor 类
			.NET Framework 提供了两种访问某类型的元数据的方式:通过 System.Reflection 命名空间中提供的反射 API,以及通过 TypeDescriptor 类.反射是可用于所有类 ... 
- [IT学习]跟阿铭学linux(第3版)
			1.安装Linux在虚拟化平台上 Windows Vmware Workstation,需要在本机上打开CPU对虚拟化的支持.Virtualization Cent OS7 已成功安装. 2.http ... 
- python  获取代码宿主机名  ip
			1.获取hostname 相同代码 不同宿主机 日志名 互异 且 可识别宿主机 分布式爬虫 https://docs.python.org/3.6/library/socket.html#socket ... 
- SAP更改日志记录表
			CDHDR 更改日志表头 CDPOS 更改日志行项目 SAP中修改频率较低的定制表(T001等)一般都会有修改记录存在,查看一个表有没有修改记录可以在SE11中查看他的技术设置,如果其中的LOG ... 
