Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sobel filter for normals from height field?

Started by Scythen Jan 20, 2006 at 7:30 PM 5 replies 5.2k views
Original Post
Scythen
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.
hplus0603
hplus0603
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.
enum Bool { True, False, FileNotFound };
python_regious
python_regious
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.
If at first you don't succeed, redefine success.
Scythen
Scythen
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.
haegarr
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.

EDIT: Look here
http://mathworld.wolfram.com/Convolution.html
for a nice animation of (not discrete but continuos) convolution.
python_regious
python_regious
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].
If at first you don't succeed, redefine success.
wolf
wolf
If you need source, you can find it in ATI's RenderMonkey ...

- Wolf

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.