Tuesday, 10 September 2013

Derivative and edge in image processing

  In the field of image processing or computer vision, edge is a very important features and being used for different purposes.Edges are boundary of the object,  like graph_01 show.Edges are one of the building block of image analysis, we could use edge detection to filter those less informative pixels and keep those informative pixels(edges).


graph_01(first deravative of horizontal and vertical sobel)

  Whenever there is a change, there is an edge. In other words,  edge are those pixels which change sharply or have discontinuities.Find the edge of image is same as find the derivative,  because derivative represent rate of change(1).To adapt it to the digital image processing, we have to come up an approximation of derivative in discrete domain, because the data of digital image processing are discrete. (2) is the approximation of (1), we pick the smallest delta x we can choose(0 is meaningless).

   Generally, there are three kind of approximation of deravative in image processing, they are backward difference(3), forward difference(4) and central difference(5).


  openCV2 provide us a function filter2D to apply correlation on the images, below are the codes which apply the x direction(graph_03) and y direction(graph_04) sobel on graph_00.

cv::Mat sobel_x_filter_ = (cv::Mat_<float>(3, 3) 
                           << -1, 0, 1,
                              -2, 0, 2,
                              -1, 0, 1),
cv::Mat sobel_y_filter_ = (cv::Mat_<float>(3, 3) 
                           << -1, -2, -1,
                               0,  0,  0,
                               1,  2,  1);

cv::Mat input = cv::imread("flower.png");
cv::Mat dst;

cv::filter2D(input_, dst, CV_8U, sobel_x_filter_);
cv::imwrite("sobel_x1.png", dst);
cv::filter2D(input_, dst, CV_8U, sobel_y_filter_);
cv::imwrite("sobel_y1.png", dst);

graph_03(first derivative of horizontal sobel)
 graph_04(first derivative of vertical sobel) 
As usual, the codes can download from github.