• Advertisement
Sign in to follow this  

Sobel filter for normals from height field?

This topic is 4475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone know how this works? I see how a Sobel filter works for edge detection but I'm not so clear on how to generate normals with it.

Share this post


Link to post
Share on other sites
Advertisement
You just generate an X and Z gradient (assuming Y is up) and then normalize.


normal.x = sobel_u( pos );
normal.y = scale;
normal.z = sobel_v( pos );
normalize( normal )


"sobel_u()" looks something like:

1 0 -1
3 0 -3
1 0 -1


"sobel_v()" looks something like:

1 3 1
0 0 0
-1 -3 -1


You may have to negate the matrices depending on your local coordinate systems.

Share this post


Link to post
Share on other sites
Quote:
Original post by Scythen
Anyone know how this works?
I see how a Sobel filter works for edge detection but I'm not so clear on how to generate normals with it.


Then you don't know how it really works for edge detection either. You can paramatise (is that the right word?) the general PDE's into difference equations. This can be expressed as a convolution of a window over the image, who's parameters are the coefficients of the terms of the difference equation. I can provide the full maths when I get home from work if you like.

Also, IIRC the standard Sobel kernel has a centre weight of 2, not 3. Not that it really matters though.

Share this post


Link to post
Share on other sites
An explanation of the maths would be great.
I think the code I was looking at was optimized leaving out parts of the original equations.

Share this post


Link to post
Share on other sites
Sobel operator are a kind of 2D filter kernel. So its mathematics is that of 2D discrete convolution
r(x,y) := ∑i,j p(x-i,y-j) * k(i,j)
(if I recall right; please verify it before use) what means that the kernel k is layed over the original image p at the location (x,y), so that one kernel element covers one pixel. Then the "pixelwise" sum over i,j defines the result r at the location (x,y).

In general the one Sobel operator lets remain horizonzal edges, while the other lets remain vertical edges, both in form of (signed) bitmaps. The amplitude of the resulting "pixels" depend in some way on the sharpness of the edges. Looking at both values together one could understand that at a normal w.r.t. to the standard normal straight high.

EDIT: Look here
http://mathworld.wolfram.com/Convolution.html
for a nice animation of (not discrete but continuos) convolution.

Share this post


Link to post
Share on other sites
Quote:
Original post by haegarr
Sobel operator are a kind of 2D filter kernel. So its mathematics is that of 2D discrete convolution
r(x,y) := ∑i,j p(x-i,y-j) * k(i,j)
(if I recall right; please verify it before use) what means that the kernel k is layed over the original image p at the location (x,y), so that one kernel element covers one pixel. Then the "pixelwise" sum over i,j defines the result r at the location (x,y).

In general the one Sobel operator lets remain horizonzal edges, while the other lets remain vertical edges, both in form of (signed) bitmaps. The amplitude of the resulting "pixels" depend in some way on the sharpness of the edges. Looking at both values together one could understand that at a normal w.r.t. to the standard normal straight high.


While this explains the idea of convolution on an image, it doesn't explain how the sobel operator works. I should be home in about an hour, so I'll post the maths then - which is really quite simple. That's if I can find my notes on it that is [wink].

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement