Robert 边缘检测算子

Posted on 2012-02-09 15:39  无忧consume  阅读(1197)  评论(0编辑  收藏  举报
Robert 边缘检测算子

#include "math.h"
// Robert算子
/*
-----------
| N2 | N3 |
-----------
| N0 | N1 |
-----------
计算公式

   sqrt((N0 - N3)2   +  (N1 - N2)2)

void Robert(BYTE* image0, BYTE* image1, unsigned int w, unsigned int h)

 int x, y, aR, aG, aB, a;
 long n;
 for(y = 0; y < h -1; ++y)
 {
  for(x = 0; x < w -1; ++x)
  {
   n = (y * w + x) * 4;

   aR = sqrt((double)((image0[n] - image0[n - w * 4 + 4]) * (image0[n] -image0[n - w * 4 + 4]) + (image0[n + 4] - image0[n - w * 4]) * (image0[n + 4] - image0[n - w * 4])));

   aG = sqrt((double)((image0[n + 1] - image0[n - w * 4 + 4 + 1]) * (image0[n + 1] -image0[n - w * 4 + 4 + 1]) + (image0[n + 4 + 1] - image0[n - w * 4 + 1]) * (image0[n + 4 + 1] - image0[n - w * 4 + 1])));

   aB = sqrt((double)((image0[n + 2] - image0[n - w * 4 + 4 + 2]) * (image0[n + 2] -image0[n - w * 4 + 4 + 2]) + (image0[n + 4 + 2] - image0[n - w * 4 + 2]) * (image0[n + 4 + 2] - image0[n - w * 4 + 2])));

   a = aR + aG + aB;

   a = a>255?255:a;
   //生成边缘扫描结果
   SetPixel(image1,n,a);
  }
 } 
}

原图:

Robert 边缘算子检测图:

Copyright © 2024 无忧consume
Powered by .NET 9.0 on Kubernetes