opencv学习(7) 一个锐化程序(有bug)

本文介绍了一个用于图像锐化的程序,详细解释了其核心功能,并提供了代码实现。通过实例演示了如何读取图像、应用锐化算法,并展示锐化效果。重点在于解决程序中尚未定位的bug。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个程序有bug,暂时还没找到原因:
/*
*本程序的主要功能是图像锐化
*2014年1月4日,
*/

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>


using namespace cv;

void imageSharpen(const Mat &image, Mat &result);

int main()
{
	Mat image = imread("D:/fodder/7.tif");
	Mat result; 
	if(!image.data)
	{
		return -1;
	}

	namedWindow("原始图像");
	imshow("原始图像", image);
	imageSharpen(image, result);
	namedWindow("锐化图像");
	imshow("锐化图像", result);

	waitKey(0);
	destroyAllWindows();

	return 0;
}

void imageSharpen(const Mat &image, Mat &result)
{
	result.create(image.size(), image.type());

	for(int j = 1; j<image.rows - 1; j++)//第一行和最后一行没有处理
	{
		const uchar* previous = image.ptr<const uchar>(j - 1);
		const uchar* current = image.ptr<const uchar>(j);
		const uchar* next = image.ptr<const uchar>(j + 1);

		uchar* output = result.ptr<uchar>(j);

		for(int i = 1; i < image.cols - 1; i++)
		{
			*output++ = saturate_cast<uchar>(5 * current[i] - current[i-1] - current[i+1] - previous[i] - next[i]);
		}
	}

	//
	result.row(0).setTo(Scalar(0));
	result.row(result.rows - 1).setTo(Scalar(0));
	result.col(0).setTo(Scalar(0));
	result.col(result.cols - 1).setTo(Scalar(0));

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值