how sobel operator works

1.7k views Asked by At

i read https://en.wikipedia.org/wiki/Sobel_operator
Say , we want to detect horizontal edges in a grey scale image.
Please Note - i have written matrix as sequence of rows.

Question 1 ) Then I should take [1,0,-1; 2,0,-2 ; 1,0,-1] (from Gx = matrix * A of wiki link above)and convolve it with given image . So I will superimpose [-1,0,1 ; -2,0,2 ; -1,0,1] (obtained from 180 degree rotation of matrix) over every pixel .
Is that right ?

Question 2 ) Suppose image is [a,b,c;d,X,f;g,h,i] then I will replace pixel X by -a+c-2d+2f-g+i=Y . What if Y turns out negative ? (pixel value can't be negative).

Question 3 ) Can I make any conclusion about a particular pixel of image by just seeing matrix obtained after applying sobel operator (not rendering that output matrix as an image) ?

Question 4 ) Is it that - depending on matrix used - horizontal or vertical edges will be emphasized in output image but not both ?

Thanks.

2

There are 2 answers

0
harold On

pixel value can't be negative

Well now it can, by definition. Using an offset representation makes it easy to visualize (flat = gray, negative = dark, positive = bright), using a 2's complement representation usually makes the math easier (but looks really bad and confusing if rendered directly). Either way if you want to use the same format (it sounds like you do, otherwise there would be no problem) you will also have to clamp and/or scale the results to the new range, because in the worst case they won't fit. Most pixels in natural images won't have a huge derivative so clamping doesn't cause too much trouble, but whether that's appropriate depends on what you need this information for. Scaling will drop small details everywhere.

Obviously if you use a different target format (with more bits per pixel than the source), this is not even an issue in the first place. If you have an 8bit input you could store the result in a signed 16bit format without any trouble.

Is it that - depending on matrix used - horizontal or vertical edges will be emphasized in output image but not both ?

Yes but you can combine them by taking the length of the gradient vector. This will treat an edge in any orientation (not just H or V, but also diagonal and angles in between) approximately equally. You could also just sum the absolute values of the horizontal and vertical derivatives, which is a simpler computation but it treats diagonal edges differently than straight edges.

0
AudioBubble On

1) right.

2) the sign will tell you the polarity of the edge; if you want to keep both polarities, take the absolute value; otherwise keep the positive or negatve part only.

3) an edge is where the response of the filter is high.

4) right, though some oblique edges will also be visible.