canny java_图像边缘检测(Canny 算法)的Java实现 | 学步园

边缘检测(1)滤波。边缘检测主要基于导数计算,但受噪声影响。但滤波器在降低噪声的同时也导致边缘强度的损失。 (2)增强。增强算法将邻域中灰度有显著变化的点突出显示。一般通过计算梯度幅值完成。

(3)检测。但在有些图象中梯度幅值较大的并不是边缘点。最简单的边缘检测是梯度幅值阈值判定。

(4)定位。精确确定边缘的位置。

Canny边缘检测算法step1:用高斯滤波器平滑图象;

step2:用一阶偏导的有限差分来计算梯度的幅值和方向;

step3:对梯度幅值进行非极大值抑制;

step4:用双阈值算法检测和连接边缘。

效果图如下:

canny2.jpg

代码如下:

packagetools;

importjava.awt.*;

importjava.awt.image.*;

publicclassEdgeDetectorextendsComponent{

publicEdgeDetector(){

threshold1 = 50;

threshold2 = 230;

setThreshold(128);

setWidGaussianKernel(15);

}

publicvoidprocess()throwsEdgeDetectorException{

if(threshold < 0 || threshold > 255)

thrownewEdgeDetectorException("The value of the threshold is out of its valid range.");

if(widGaussianKernel < 3 || widGaussianKernel > 40)

thrownewEdgeDetectorException("The value of the widGaussianKernel is out of its valid range.");

width = sourceImage.getWidth(this);

height = sourceImage.getHeight(this);

picsize = width * height;

data =newint[picsize];

magnitude =newint[

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值