【算法学习】【图像增强】【Retinex】White Patch Retinex 程序解读
2015-07-28 09:53
1341 查看
%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; end out = 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);%获取输出图像 end elseif ( para == 1 ) % more robust algorithm np = 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>1 j = j-1; sum = sum + H(j); %累加直方图值 end L(i) = j; out(:,:,i) = inDouble(:,:,i)/L(i);%输出图 end end end
接着前面的一篇介绍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');
运行效果图:
相关文章推荐
- 解析在main函数之前调用函数以及对设计的作用详解
- java和matlab画多边形闭合折线图示例讲解
- C#调用Matlab生成的dll方法的详细说明
- 从java中调用matlab详细介绍
- VC++与Matlab混合编程的快速实现
- Matlab 矩阵运算
- matlab与opencv部分函数的对照
- matlab神经网络工具箱创建神经网络
- Matlab
- MATLAB 入门教程
- matlab函数_连通区域
- MATLAB中函数模式和命令模式的区别
- MATLAB 添加自定义的模块到simulink库浏览器
- MATLAB for Mac使编辑器支持中文
- [转]matlab中plot用法
- matlab程序优化以及eclipse与github的结合
- matlab中的rand函数(用于产生随机数)
- 图像增强算法四种,图示与源码,包括retinex(ssr、msr、msrcr)和一种混合算法
- MATLAB R2012a 安装到 Ubuntu 12.10
- 智慧网 分享DCT,DST,matlab