OpenCV - Calculating edge strength of image

1.7k views Asked by At

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..?

1

There are 1 answers

0
beaker On

mean will give you the mean value of your image. If you're using Canny as above you can do:

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. 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.