2
$\begingroup$

In image processing and especially edge detection, when we apply sobel convolution matrix to a given image, we say that we got the first derivative of the input image, and when applying the laplacian matrix to the initial image we say that we got the second derivative.

Taking into consideration that in both cases we applied the same operation (img * matrix), then why the first operation gave us the first derivative, and the second one gave us the second derivative and not the fifth ? is the values of the mask (convolution matrix) which decide which derivative we got ? or I'm already mistaken in my description ?

$\endgroup$
2
  • $\begingroup$ en.wikipedia.org/wiki/Finite_difference $\endgroup$
    – Atul Ingle
    Nov 3, 2017 at 20:49
  • $\begingroup$ I'm null in mathematics, if you have a logical response away from maths please post it and I'll mark it as the best answer $\endgroup$
    – Reda LM
    Nov 3, 2017 at 21:38

2 Answers 2

17
$\begingroup$

Look at the numbers in the filter kernel in just 1 dimension for simplicity. For a Sobel and Prewitt matrix you have something that roughly looks like this

[-1,0,1].

Convolving this with your image basically computes the difference between the pixel values of the neighboring pixels. You apply 0 to the current pixel, 1 to the pixel on the right and -1 to the pixel on the left. This gives a first order difference:

next pixel - previous pixel,

i.e. first derivative.

But now look at a Laplacian operator. It looks something like [1, -2, 1]. This computes the difference of differences. To see how, note that

[1,-2,1] corresponds to

next - 2 x current + previous

i.e.

next - current - current + previous

i.e.

(next-current) - (current-previous)

Now notice how this is a diference of differences. (next - current) is like a 1st derivative. (current - previous) is like 1st derivative. Their difference is like a 2nd derivative.

$\endgroup$
3
  • $\begingroup$ That's what I was looking for, thank's @Atul $\endgroup$
    – Reda LM
    Nov 3, 2017 at 23:05
  • $\begingroup$ What would be a 3rd image derivative? $\endgroup$
    – mpnm
    Aug 19, 2021 at 1:11
  • $\begingroup$ @mpnm You can apply the "next pixel minus previous pixel" operation to the Laplacian of the image. That should give you the third derivative. $\endgroup$
    – Atul Ingle
    Aug 19, 2021 at 16:44
2
$\begingroup$

Operations like img$*$matrix are, in a generic, all convolutions. And derivatives are instance of convolutions. But convolutions are much more generic. When looking at edges, one can use derivatives at different orders. So you can have different such matrices representing different derivatives. If you convolve two such matrices representing a first derivative, you can get matrix$*$matrix, which is just another kind of (convolution) matrix, but now representing a second derivative (under some conditions I won't detail now).

[EDIT after Atul Ingle] The choice of the coefficients in img drives its behavior. On a discrete image, img can emulate different discretized derivative behaviors, potentially in different directions. Discretizing oriented operators is a complex operations. For instance, you can find here at least three different $3\times 3$ versions for the discrete Laplacian:

discrete Laplacian

Here, are two recent references if you want to dig deeper:

This paper proposes a corner detector and classifier using anisotropic directional derivative (ANDD) representations. The ANDD representation at a pixel is a function of the oriented angle and characterizes the local directional grayscale variation around the pixel. The proposed corner detector fuses the ideas of the contour- and intensity-based detection. It consists of three cascaded blocks. First, the edge map of an image is obtained by the Canny detector and from which contours are extracted and patched. Next, the ANDD representation at each pixel on contours is calculated and normalized by its maximal magnitude. The area surrounded by the normalized ANDD representation forms a new corner measure. Finally, the nonmaximum suppression and thresholding are operated on each contour to find corners in terms of the corner measure. Moreover, a corner classifier based on the peak number of the ANDD representation is given. Experiments are made to evaluate the proposed detector and classifier. The proposed detector is competitive with the two recent state-of-the-art corner detectors, the He & Yung detector and CPDA detector, in detection capability and attains higher repeatability under affine transforms. The proposed classifier can discriminate effectively simple corners, Y-type corners, and higher order corners.

We describe the design of finite-size linear-phase separable kernels for differentiation of discrete multidimensional signals. The problem is formulated as an optimization of the rotation-invariance of the gradient operator, which results in a simultaneous constraint on a set of one-dimensional low-pass prefilter and differentiator filters up to the desired order. We also develop extensions of this formulation to both higher dimensions and higher order directional derivatives. We develop a numerical procedure for optimizing the constraint, and demonstrate its use in constructing a set of example filters. The resulting filters are significantly more accurate than those commonly used in the image and multidimensional signal processing literature.

$\endgroup$
2
  • $\begingroup$ Thank's for your answer @Laurent , but I'm afraid that this don't answer my question yet, I just want to understand why sometimes img*matrix give us the first derivative (sobel, prewitt..), and at other times it give us the second derivative (laplacian...). $\endgroup$
    – Reda LM
    Nov 3, 2017 at 22:29
  • 2
    $\begingroup$ @RedaLM That's due to the numbers in the filter matrix. If you have something like [-1,0,1] it is taking the difference between neighboring pixel values i.e. 1st derivative. But if you have something like [1,-2,1] it's taking the difference of the difference i.e. 2nd derivative. $\endgroup$
    – Atul Ingle
    Nov 3, 2017 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.