清晰度

void get_raidu_parameter(BYTE * greyBuffer, int width, int height, float & raidu, int & pixelCount)
{
 USHORT* sobel = new USHORT[width*height];
 memset(sobel, 0, width*height*sizeof(USHORT));

 int x, y, v10, v11, v12;

 for (y = 1; y < height - 1; y++)
 {
  for (x = 1; x < width - 1; x++)
  {
   *POINT2D_BUF(sobel, width, x, y) = abs(
    GET2D_BUF(greyBuffer, width, x - 1, y - 1) +
    2 * GET2D_BUF(greyBuffer, width, x - 1, y) +
    GET2D_BUF(greyBuffer, width, x - 1, y + 1) -
    GET2D_BUF(greyBuffer, width, x + 1, y - 1) -
    2 * GET2D_BUF(greyBuffer, width, x + 1, y) -
    GET2D_BUF(greyBuffer, width, x + 1, y + 1));
  }
 }

 std::vector<POINT> listPixels;
 POINT pt;

 for (y = 1; y < height - 1; y++)
 {
  for (x = 1; x < width - 1; x++)
  {
   v11 = GET2D_BUF(sobel, width, x, y);
   v10 = GET2D_BUF(sobel, width, x - 1, y);
   v12 = GET2D_BUF(sobel, width, x + 1, y);

   if ((v11 >= 50) && (v11 > v10) && (v11 > v12))
   {
    pt.x = x;
    pt.y = y;
    listPixels.push_back(pt);
   }
  }
 }
 delete[] sobel;

 if (listPixels.size() == 0)
  return;

 int total = 0;
 int tmp, sameCount, x3;

 const BYTE MAX_VAL = 50;
 const BYTE THREE = 3;
 const BYTE FIVE = 5;
 bool isBlack;

 std::vector<POINT>::iterator it;
 for (it = listPixels.begin(); it != listPixels.end(); it++)
 {
  x = it->x;
  y = it->y;

  sameCount = 0;
  isBlack = (GET2D_BUF(greyBuffer, width, x, y) <= GET2D_BUF(greyBuffer, width, x - 1, y));

  for (int x2 = x; x2 > 0; x2--)
  {
   sameCount++;
   if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x2 - 1, y)) > MAX_VAL)//急变点,跳出
    break;

   if (isBlack) //暗点
   {
    if (GET2D_BUF(greyBuffer, width, x2, y) > GET2D_BUF(greyBuffer, width, x2 - 1, y))//转折点,跳出
     break;
   }
   else//亮点
   {
    if (GET2D_BUF(greyBuffer, width, x2, y) < GET2D_BUF(greyBuffer, width, x2 - 1, y))//转折点,跳出
     break;
   }

   tmp = 0;
   for (x3 = x2; x3 > 0; x3--)
   {
    if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x3, y)) < THREE)
    {
     tmp++;
     if (tmp > FIVE)
      break;
    }
    else
     break;
   }

   if (tmp > FIVE)//相似点超过5个,跳出
    break;
  }

  isBlack = (GET2D_BUF(greyBuffer, width, x, y) <= GET2D_BUF(greyBuffer, width, x + 1, y));

  for (int x2 = x; x2 < width; x2++)
  {
   sameCount++;
   if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x2 + 1, y)) > MAX_VAL)
    break;

   if (isBlack)
   {
    if (GET2D_BUF(greyBuffer, width, x2, y) > GET2D_BUF(greyBuffer, width, x2 + 1, y))
     break;
   }
   else
   {
    if (GET2D_BUF(greyBuffer, width, x2, y) < GET2D_BUF(greyBuffer, width, x2 + 1, y))
     break;
   }

   tmp = 0;
   for (x3 = x2; x3 < width; x3++)
   {
    if (abs(GET2D_BUF(greyBuffer, width, x2, y) - GET2D_BUF(greyBuffer, width, x3, y)) < THREE)
    {
     tmp++;
     if (tmp > FIVE)
      break;
    }
    else
     break;
   }

   if (tmp > FIVE)
    break;
  }
  sameCount--;
  total += sameCount;
 }

 raidu = (float)total * 100.0 / listPixels.size();
 pixelCount = listPixels.size();
 printf("%.4f, total=%d, pixel_count=%d \n", raidu, total, pixelCount);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值