【算法学习】【图像增强】【Retinex】White Patch Retinex 程序解读

来源:互联网 发布:cp什么意思网络用语 编辑:程序博客网 时间:2024/05/17 04:51
%para=0代表原始方法,para=1代表改进后的方法function out = WhitePatchRetinex(in,para)%UNTITLED Summary of this function goes here%   Detailed explanation goes here%%%%copyright: ofalling %%%%if( nargin < 2 )para = 0;endout = zeros(size(in));            %out定义一个和输入图像同等大小的零矩阵inDouble = double(in);            %将图像转换为double型L = [0 0 0];                      %定义一个行向量,用于存放光源的三个通道的值if ( para == 0 )                  %para=0,表示采用原始方法for i = 1:3             L(i) = max(max(in(:,:,i)));       %分别获取三个通道中的最大值out(:,:,i) = inDouble(:,:,i)/L(i);%获取输出图像endelseif ( para == 1 )              % more robust algorithmnp = 0.1 * size(in,1)*size(in,2); %获取总像素个数的10%for i = 1:3                         H = imhist(in(:,:,i));            %每个通道的直方图j = 256;sum = 0;while( (sum < np)&(j > 1) )       %只要像素点个数没有统计完,并且j>1j = j-1;sum = sum + H(j);                 %累加直方图值endL(i) = j;out(:,:,i) = inDouble(:,:,i)/L(i);%输出图endendend

    接着前面的一篇介绍White Patch Retinex算法的介绍,自己试着运行了一下程序,由于自己电脑所带的版本为Matlab2010,该版本还没有White Patch Retinex算法,所以需要自己新建该函数(File->New->Function),函数的代码如上所示,封装完之后,采用如下方式调用该函数出现下面的错误:


将程序代码部分执行发现:

out=zeros(size('D:\123.jpg'))
输出为:
out =     0     0     0     0     0     0     0     0     0     0

所以采用这种输入方式是不正确的:需要用imread函数读取图像后赋值给一个变量再显示。

调用程序:

A=imread('D:\123.png');A1= WhitePatchRetinex(A,0);A2=WhitePatchRetinex(A,1);B1=imread('D:\124.png');B2=WhitePatchRetinex(B1,0);B3=WhitePatchRetinex(B1,1);subplot(231),imshow(B1);title('input1');subplot(232),imshow(B2);title('White Patch Retinex');subplot(233),imshow(B3);title('Modified White Patch Retinex');subplot(234),imshow(A);title('input2');subplot(235),imshow(A1);title('White Patch Retinex');subplot(236),imshow(A2);title('Modified White Patch Retinex');

运行效果图:





0 0
原创粉丝点击