C语言实现图像锐化

void SharpenInt(unsigned int *_src, unsigned int *_dst, int _width, int _height)
{

	int *Ix = tmpBuff;
	int *Iy = tmpBuff + _width * _height * sizeof(int);

	// 求梯度
	for (int y = 0; y < _height; y++)
	{
		int offset = y * _width;
		Ix[offset] = abs((int)_src[offset + 1] - (int)_src[offset]) * 2;
		for (int x = 1; x < _width - 1; x++)
			Ix[offset + x] = abs((int)_src[offset + x + 1] - (int)_src[offset + x - 1]);
		Ix[offset + _width - 1] = abs((int)_src[offset + _width - 1] - (int)_src[offset + _width - 2]) * 2;
	}
	for (int x = 0; x < _width; x++)
	{
		Iy[x] = abs((int)_src[_width + x] - (int)_src[x]) * 2;
		for (int y = 1; y < _height - 1; y++)
			Iy[y * _width + x] = abs((int)_src[(y + 1) * _width + x] - (int)_src[(y - 1) * _width + x]);
		Iy[(_height - 1) * _width + x] = abs((int)_src[(_height - 1) * _width + x] - (int)_src[(_height - 2) * _width + x]) * 2;
	}
	for (int y = 0; y < _height; y++)
	{
		int offset = y * _width;
		for (int x = 0; x < _width; x++)
		{
			int temp = _src[offset + x] + Ix[offset + x] + Iy[offset + x];
			//CUTOFF(temp, 0, 255);
			_dst[offset + x] = (unsigned int)temp;
		}
	}
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值