Laan's steps..

Feed Rss

基于ConvolutionFilter的图像边缘检测[摘]

03.13.2009, flash, by .

原文请查看:http://vanillaloveyou.spaces.live.com/blog/cns!9eead40c443bb757!188.entry

一、Krisch边缘算子

//中值虑镜
var smoothFilter:ConvolutionFilter = new ConvolutionFilter(3, 3, [1, 1, 1, 1, 1, 1, 1, 1, 1], 9, 0);

//krisch 算子虑镜
var krischFilter1:ConvolutionFilter = new ConvolutionFilter(3, 3, [5, 5, 5, -3, 0, -3, -3, -3, -3]);
var krischFilter2:ConvolutionFilter = new ConvolutionFilter(3, 3, [-3, 5, 5, -3, 0, 5, -3, -3, -3]);
var krischFilter3:ConvolutionFilter = new ConvolutionFilter(3, 3, [-3, -3, 5, -3, 0, 5, -3, -3, 5]);
var krischFilter4:ConvolutionFilter = new ConvolutionFilter(3, 3, [-3, -3, -3, -3, 0, 5, -3, 5, 5]);
var krischFilter5:ConvolutionFilter = new ConvolutionFilter(3, 3, [-3, -3, -3, -3, 0, -3, 5, 5, 5]);
var krischFilter6:ConvolutionFilter = new ConvolutionFilter(3, 3, [-3, -3, -3, 5, 0, -3, 5, 5, -3]);
var krischFilter7:ConvolutionFilter = new ConvolutionFilter(3, 3, [5, -3, -3, 5, 0, -3, 5, -3, -3]);
var krischFilter8:ConvolutionFilter = new ConvolutionFilter(3, 3, [5, 5, -3, 5, 0, -3, -3, -3, -3]);

//
var thresholdValue = 70;
var thresholdCondition = “<”;
var thresholdColor = 0xffffffff;

//
var bmpRes:BitmapData = new BitmapData(mc._width, mc._height);
var bmpCur:BitmapData = new BitmapData(mc._width, mc._height);

//
function process() {
bmpCur.draw(mc);
bmpCur.applyFilter(bmpCur, bmpCur.rectangle, new Point(0, 0), smoothFilter);
//
var motionRect:Rectangle = bmpCur.rectangle;
//
for (var i = 1; i<9; i++) {
var tmp = new BitmapData(motionRect.width, motionRect.height);
tmp.copyPixels(bmpCur, motionRect, new Point(motionRect.x, motionRect.y));
tmp.applyFilter(tmp, tmp.rectangle, new Point(0, 0), this["krischFilter"+i]);
bmpRes.draw(tmp, new Matrix(), null, “substract”, bmpRes.rectangle);
}
//Red Channel
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), thresholdCondition, thresholdValue << 16, thresholdColor, 0x00FF0000, false);
//Green Channel
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), thresholdCondition, thresholdValue << 8, thresholdColor, 0x000000ff, false);
//Blue Channel
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), thresholdCondition, thresholdValue, thresholdColor, 0x000000ff, false);
//Change other color to White
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), “<”, 0xffffff, 0xff000000, 0x00ffffff, false);
}

Krish算子对于递增方向极其敏感,最佳的方向就是最大梯度幅度响应的方向,检测边缘效果较好,噪声抑制能力较强

二、高斯-拉普拉斯算子

//中值虑镜
var smoothFilter:ConvolutionFilter = new ConvolutionFilter(3, 3, [1, 1, 1, 1, 1, 1, 1, 1, 1], 9, 0);

//5×5高斯虑镜
var guassLaplaceFilter3:ConvolutionFilter = new ConvolutionFilter(5, 5, [-2, -4, -4, -4, -2, -4, 0, 8, 0, -4, -4, 8, 24, 8, -4, -4, 0, 8, 0, -4, -2, -4, -4, -4, -2]);

//
var bmpRes:BitmapData = new BitmapData(mc._width, mc._height);
var bmpCur:BitmapData = new BitmapData(mc._width, mc._height);

//
var thresholdValue = 5;
var thresholdCondition = “>”;
var thresholdColor = 0xffffffff;

function process() {
bmpCur.draw(mc);
bmpCur.applyFilter(bmpCur, bmpCur.rectangle, new Point(0, 0), smoothFilter);
//
var motionRect:Rectangle = bmpCur.rectangle;
//
var tmp = new BitmapData(motionRect.width, motionRect.height);
tmp.copyPixels(bmpCur, motionRect, new Point(motionRect.x, motionRect.y));
tmp.applyFilter(tmp, tmp.rectangle, new Point(0, 0), this["guassLaplaceFilter3"]);
bmpRes.draw(tmp, new Matrix(), null, “difference”, bmpRes.rectangle);
//Red Channel
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), thresholdCondition, thresholdValue << 16, thresholdColor, 0x00FF0000, false);
//Green Channel
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), thresholdCondition, thresholdValue << 8, thresholdColor, 0x000000ff, false);
//Blue Channel
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), thresholdCondition, thresholdValue, thresholdColor, 0x000000ff, false);
//Change other color to White
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), “<”, 0xffffff, 0xff000000, 0x00ffffff, false);
}
高斯-拉普拉斯算子通过检测二阶导数过零点来判断边缘点,检测效果较好,由于5×5模板采用了平滑去躁,效果更佳。

三、Prewitt算子

var smoothFilter:ConvolutionFilter = new ConvolutionFilter(3, 3, [1, 1, 1, 1, 1, 1, 1, 1, 1], 9, 0);

//
var prewittFilter1:ConvolutionFilter = new ConvolutionFilter(3, 3, [-1, -1, -1, 0, 0, 0, 1, 1, 1]);
var prewittFilter2:ConvolutionFilter = new ConvolutionFilter(3, 3, [-1, -1, 0, -1, 0, 1, 0, 1, 1]);
var prewittFilter3:ConvolutionFilter = new ConvolutionFilter(3, 3, [-1, 0, 1, -1, 0, 1, -1, 0, 1]);
var prewittFilter4:ConvolutionFilter = new ConvolutionFilter(3, 3, [0, 1, 1, -1, 0, 1, -1, -1, 0]);
var prewittFilter5:ConvolutionFilter = new ConvolutionFilter(3, 3, [1, 1, 1, 0, 0, 0, -1, -1, -1]);
var prewittFilter6:ConvolutionFilter = new ConvolutionFilter(3, 3, [1, 1, 0, 1, 0, -1, 0, -1, -1]);
var prewittFilter7:ConvolutionFilter = new ConvolutionFilter(3, 3, [1, 0, -1, 1, 0, -1, 1, 0, -1]);
var prewittFilter8:ConvolutionFilter = new ConvolutionFilter(3, 3, [-1, -1, -1, 0, 0, 0, 1, 1, 1]);

//
var bmpRes:BitmapData = new BitmapData(mc._width, mc._height);
var bmpCur:BitmapData = new BitmapData(mc._width, mc._height);

//
var thresholdValue = 50;
var thresholdCondition = “<”;
var thresholdColor = 0xff000000;

….

for (var i = 1; i<9; i++) {
var tmp = new BitmapData(motionRect.width, motionRect.height);
tmp.copyPixels(bmpCur, motionRect, new Point(motionRect.x, motionRect.y));
tmp.applyFilter(tmp, tmp.rectangle, new Point(0, 0), this["prewittFilter"+i]);
bmpRes.draw(tmp, new Matrix(), null, “substract”, bmpRes.rectangle);
}
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), thresholdCondition, thresholdValue << 16, thresholdColor, 0x00FF0000, false);
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), thresholdCondition, thresholdValue << 8, thresholdColor, 0x000000ff, false);
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), thresholdCondition, thresholdValue, thresholdColor, 0x000000ff, false);
bmpRes.threshold(bmpRes, bmpRes.rectangle, new Point(0, 0), “>”, 0×0, 0xffffffff, 0x00ffffff, false);
Prewitt算子检测能更清楚,便于识别

基于ConvolutionFilter的图像边缘检测[摘] 有1条回应

  1. 呵呵 啥时候也研究这个啦 这里基本都是通过卷积实现的

    回复

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>