基于相似性的空域去燥

void spatialWeightingDeNoise(unsigned char* dst, unsigned char* src, int width, int height, int srcStride, int dstStride, int radius)
{
	int offsetAddr = radius * dstStride + radius;
	int boxLength  = 2 * radius + 1;
	int boxSize    = BOX_SIZE;
	float weight[BOX_SIZE] = { 0 };

	for (int h = 0; h < height; h++)
	{
		for (int w = 0; w < width; w++)
		{
			unsigned char* boxSrc = src + w - offsetAddr;
			float difSum = 0;

			for (int i = 0,idx = 0; i < boxLength; i++)
			{
				for (int j = 0; j < boxLength; j++)
				{
					weight[idx] = 1.f * abs(boxSrc[j] - src[w]);
					difSum     += weight[idx];
					idx++;
				}
				boxSrc += dstStride;
			}

			float weightSum = 0;
			for (int idx = 0; idx < boxSize; idx++)
			{
				weight[idx] = 1 - weight[idx] / (difSum + 0.1f);
				weightSum  += weight[idx];
			}

			boxSrc = src + w - offsetAddr;
			float weightDst = 0;
			for (int i = 0, idx = 0; i < boxLength; i++)
			{
				for (int j = 0; j < boxLength; j++)
				{
					weight[idx] = weight[idx] / weightSum;
					weightDst  += weight[idx] * boxSrc[j];
					idx++;
				}
				boxSrc += dstStride;
			}
			dst[w] = (unsigned char)(weightDst > 255 ? 255 : weightDst);
		}
		src += srcStride;
		dst += dstStride;
	 }
}

void padding(unsigned char* dst, unsigned char* src, int width, int height, int srcStride, int dstStride, int padSize)
{
	int offsetAddr = padSize * dstStride + padSize;
	unsigned char* dstTmp = dst + offsetAddr;

	for (int h = 0; h < height; h++)
	{
		memcpy(dstTmp, src, srcStride * sizeof(*src));
		src    += srcStride;
		dstTmp += dstStride;
	}
	
	dstTmp = dst + padSize * dstStride;
	for (int h = 0; h < height; h++)
	{
		unsigned char leftVal  = dstTmp[padSize];
		unsigned char rightVal = dstTmp[padSize + width - 1];
		for (int w = 0; w < padSize; w++)
		{
			dstTmp[w]                   = leftVal;
			dstTmp[width + padSize + w] = rightVal;
		}
		dstTmp += dstStride;
	}

	dstTmp = dst;
	unsigned char* dstTop = dst + padSize * dstStride;
	for (int h = 0; h < padSize; h++)
	{
		memcpy(dstTmp, dstTop, dstStride * sizeof(*dst));
		dstTmp += dstStride;
	}
																
	dstTmp = dst + (height + padSize) * dstStride;
	unsigned char* dstbotom = dstTmp - dstStride;
	for (int h = 0; h < padSize; h++)
	{
		memcpy(dstTmp, dstbotom, dstStride * sizeof(*dst));
		dstTmp += dstStride;
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值