【图像处理】基本图像处理算法原理与实现四:边缘检测

                                              边缘检测

1、基于模板的边缘检测(Sobel和Prewitt)

这种边缘检测是将灰度图像使用对应的锐化算子进行增强处理,然后对其进行二值化。

实现代码:

/*****************************************************************************
函数名		:	ImgEdgeSobel
功能		:	Sobel边缘检测
算法实现	:	<可选项>
参数说明	:	tSrcImg 原图像[in]
				ptDstImg 目标图像[out]
				u8Thresh 阈值[in]
				u8SenDir 敏感方向(SOBEL_SENDIRH 水平;SOBEL_SENDIRV 垂直)[in]
返回值说明	:	无
其他说明	:	无
******************************************************************************/
void ImgEdgeSobel(MyImage tSrcImg, MyImage *ptDstImg, u8 u8Thresh, u8 u8SenDir)
{
	f32 f32SobelFilterV[9] = { -1, 0, 1,
							   -2, 0, 2,
							   -1, 0, 1 };
	f32 f32SobelFilterH[9] = { -1, -2, -1,
							    0, 0, 0,
							    1, 2, 1 };
	MyImage MyImgGray, MyImgSobel;
	ImgRGBToGray(tSrcImg, &MyImgGray);
	switch(u8SenDir)
	{
		case SOBEL_SENDIRH:
			ImgFilter(MyImgGray, &MyImgSobel, f32SobelFilterH, 3, 3);
			break;
		case SOBEL_SENDIRV:
			ImgFilter(MyImgGray, &MyImgSobel, f32SobelFilterV, 3, 3);
			break;
		default:break;
	}
	ImgGrayToBina(MyImgSobel, ptDstImg, u8Thresh);
}

/*****************************************************************************
函数名		:	ImgEdgePrewitt
功能		:	Prewitt边缘检测
算法实现	:	<可选项>
参数说明	:	tSrcImg 原图像[in]
				ptDstImg 目标图像[out]
				u8Thresh 阈值[in]
				u8SenDir 敏感方向(PREWITT_SENDIRH 水平;PREWITT_SENDIRV 垂直)[in]
返回值说明	:	无
其他说明	:	无
******************************************************************************/
void ImgEdgePrewitt(MyImage tSrcImg, MyImage *ptDstImg, u8 u8Thresh, u8 u8SenDir)
{
	f32 f32PrewittFilterV[9] = { -1, 0, 1,
		-1, 0, 1,
		-1, 0, 1 };
	f32 f32PrewittFilterH[9] = { -1, -1, -1,
		0, 0, 0,
		1, 1, 1 };

	MyImage MyImgGray, MyImgPrewitt;
	ImgRGBToGray(tSrcImg, &MyImgGray);
	switch (u8SenDir)
	{
	case PREWITT_SENDIRH:
		ImgFilter(MyImgGray, &MyImgPrewitt, f32PrewittFilterH, 3, 3);
		break;
	case PREWITT_SENDIRV:
		ImgFilter(MyImgGray, &MyImgPrewitt, f32PrewittFilterV, 3, 3);
		break;
	default:break;
	}
	ImgGrayToBina(MyImgPrewitt, ptDstImg, u8Thresh);
}

2、Canny边缘检测

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值