2
$\begingroup$

Let $A$ be a image matrix and let $P(i,j)$ be the gray level of pixel $i,j$. Let $0$ be black and $255$ be white Assume I want to differentiate this image with respect to the columns $(x)$ as in I want $P(i,j)=P(i,j+1)-P(i,j)$ in the new image.

I get that I can achieve this with convolution of $A$ with the filter $f = [1 \ -1]$ since you flip the filter in the $x-$direction (so pixel $i,j$ would be multiplied by $-1$ and $i,j+1$ with $1$ which gives me what I want.

My understanding is that this process is supposed to highlight differences in the $x-$direction.

Two questions:

  1. How does the gray-level scale in the resulting image work? If one pixel had gray level $240$ and the next pixel had gray level $5$, this would result in the new pixel having the gray level $-235$, what does that mean in the scale of $0$ to $255$? Does my scale change from $0...255$ to $-255...255$?

  2. Does it matter if I convolve $A$ with the filter $[-1 \ 1]$ instead of $[1 \ -1]$?. What would be the result?

$\endgroup$
  • 1
    $\begingroup$ The [-1 1] is a discrete approximation of first derivative.The sign of the outcome define the slope of variation in intensity. Also the the 0-255 is a limitation by uint8 type (values outside 0-255 considered as overflow). And for your second question, these two would be exactly negative of each other. $\endgroup$ – Mohammad M Sep 20 at 17:01
3
$\begingroup$

Your interpretation is correct: directional derivation operators highlight variation in a given direction. Here, you use the $2$-point discrete derivative in the $x$-direction (along image rows). It may emphasize vertical features.

First, such operators indeed extend the initial image range. However, one often uses the absolute value of the derivative to compute a gradient. With the modulus, the derivative values fall back in the initial image range.

Second, as $[1 \;-1] = -[-1\; 1]$, and since convolution is a linear operator, you will get the opposite result as in the previous case. And it won't matter if you take the absolute value.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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