C++实现卷积操作

本文详细介绍了如何使用C++编程语言实现卷积操作,包括相关算法和步骤,为理解和应用卷积提供了实践指导。
摘要由CSDN通过智能技术生成

卷积操作的C++实现

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

using namespace  std;
using namespace  cv;

Mat Kernel_test_3_3 = (
	Mat_<double>(3, 3) <<
	0, -1, 0,
	-1, 5, -1,
	0, -1, 0);
void Convlution(Mat  InputImage, Mat  OutputImage, Mat kernel)
{
	//计算卷积核的半径
	int sub_x = kernel.cols / 2;
	int sub_y = kernel.rows / 2;
	//遍历图片  
	for (int image_y = 0; image_y < InputImage.rows - 2 * sub_y; image_y++)
	{
		for (int image_x = 0; image_x < InputImage.cols - 2 * sub_x; image_x++)
		{
			int pix_value = 0;
			for (int kernel_y = 0; kernel_y < kernel.rows; kernel_y++)
			{
				for (int kernel_x = 0; kernel_x < kernel.cols; kernel_x++)
				{
					double  weihgt = kernel.at<double>(kernel_y, kernel_x);
					int value = (int)InputImage.at<uchar>(image_y + kernel_y, im
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值