资源简介
适用于vs2010的图像处理算法,包括SSR,MSR,MSRCR等retinex改进算法,方便大家学习交流和项目开发,有问题请随时提问。
。
代码片段和文件信息
#include “MSRCR.h“
/*===========================================================
* 函数: CreateKernel
* 说明:创建一个标准化的一维高斯核;
* 参数:
* double sigma: 高斯核标准偏差
* 返回值:
* double*: 长度为((6*sigma)/2) * 2 + 1的double数组
* 注:
* 调用者需要删除该内核;
* --------------------------------------------------------
* Summary:
* Creates a normalized 1 dimensional gaussian kernel.
*
* Arguments:
* double sigma - the standard deviation of the gaussian kernel.
*
* Returns:
* vector - an vector of values of length ((6*sigma)/2) * 2 + 1.
* Note:
* Caller is responsable for deleting the kernel.
=============================================================
*/
vector Msrcr::CreateKernel(double sigma)
{
int i x filter_size;
vector filter;
double sum;
// set sigma‘s upline
// 为sigma设定上限
if ( sigma > 300 ) sigma = 300;
// get needed filter size (enforce oddness)
// 获取需要的滤波尺寸,且强制为奇数;
filter_size = (int)floor(sigma*6) / 2;
filter_size = filter_size * 2 + 1;
// Calculate exponential
// 计算指数
sum = 0;
for (i = 0; i < filter_size; i++)
{
double tmpValue;
x = i - (filter_size / 2);
tmpValue = exp( -(x*x) / (2*sigma*sigma) );
filter.push_back(tmpValue);
sum += tmpValue;
}
// Normalize
// 归一化计算
for (i = 0 x; i < filter_size; i++)
filter[i] /= sum;
return filter;
}
/*===========================================================
* 函数: CreateFastKernel
* 说明:创建一个近似浮点的整数类型(左移8bits)的快速高斯核;
* 参数:
* double sigma: 高斯核标准偏差
* 返回值:
* double*: 长度为((6*sigma)/2) * 2 + 1的int数组
* 注:
* 调用者需要删除该内核;
* --------------------------------------------------------
* Summary:
* Creates a faster gaussian kernal using integers that
* approximate floating point (leftshifted by 8 bits)
*
* Arguments:
* double sigma - the standard deviation of the gaussian kernel.
*
* Returns:
* vector - an vector of values of length ((6*sigma)/2) * 2 + 1.
*
* Note:
* Caller is responsable for deleting the kernel.
=============================================================
*/
vector Msrcr::CreateFastKernel(double sigma)
{
vector fp_kernel;
vector kernel;
int i filter_size;
// Reject unreasonable demands
// 设置上限
if ( sigma > 300 ) sigma = 300;
// get needed filter size (enforce oddness)
// 获取需要的滤波尺寸,且强制为奇数;
filter_size = (int)floor(sigma*6) / 2;
filter_size = filter_size * 2 + 1;
// Create Kernel
// 创建内核
fp_kernel = CreateKernel(sigma);
// Change kernel‘s data type from double to int
// double内核转为int型
for (i = 0; i < filter_size; i++)
{
int tmpValue;
tmpValue = double2int(fp_kernel[i]);
kernel.push_back(tmpValue);
}
return kernel;
}
/*===========================================================
* 函数:FilterGaussian
* 说明:通过内核计算高斯卷积,内核由sigma值得到,且在内核两端值相等;
* 参数:
* img: 被滤波的IplImage*类型图像
* double sigma: 高斯核标准偏差
* -----------------------------------------
评论
共有 条评论