简体   繁体   English

OpenCV-计算图像的边缘强度

[英]OpenCV - Calculating edge strength of image

I am new to image processing and I need to calculate the strength of edges present in an image. 我是图像处理的新手,我需要计算图像中边缘的强度。 Assume a situation where you have an image and you add blur effect to that image. 假设您有一个图像,并且对该图像添加了模糊效果。 The strength of the edges of these two images are different. 这两个图像的边缘强度不同。 I need to calculate that edge strength for both images separately. 我需要单独计算两者图像边缘强度。

So far I have got the canny edge detection of the image using the code below. 到目前为止,我已经使用下面的代码对图像进行了边缘检测。

  Mat src1;
  src1 = imread("D.PNG", CV_LOAD_IMAGE_COLOR);
  namedWindow("Original image", CV_WINDOW_AUTOSIZE);
  imshow("Original image", src1);
  Mat gray, edge, draw;
  cvtColor(src1, gray, CV_BGR2GRAY);
  Canny(gray, edge, 50, 150, 3);
  edge.convertTo(draw, CV_8U);
  namedWindow("image", CV_WINDOW_AUTOSIZE);
  imshow("image", draw);
  waitKey(0);
  return 0;

Is there any method to calculate of the strength of this edge image..? 有什么方法可以计算出边缘图像的强度吗?

mean will give you the mean value of your image. mean将为您提供图像的平均值。 If you're using Canny as above you can do: 如果您如上所述使用Canny ,则可以执行以下操作:

Scalar pixelMean = mean(draw);

To get the mean of only the edge pixels, you would use the image as the mask as well: 要仅获取边缘像素的均值,还可以使用图像作为遮罩:

Scalar edgeMean = mean(draw, draw);

Unfortunately, since Canny sets all edge pixels to 255 , your mean will always be 255 . 不幸的是,由于Canny将所有边缘像素都设置为255 ,因此您的均值将始终为255 If this is the measure you're looking for, you'll probably want to use Sobel (after Gaussian Blur) and calculate the gradients to get the relative edge strengths. 如果这是您要寻找的量度,则可能要使用Sobel (在高斯模糊之后)并计算渐变以获得相对边缘强度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM