grayscale to slope/inclination grayscale

Hi
I have a bw(grayscale) image and want to calculate the slope for each pixel which returns a value 0 to 255 value.

Pixels are always between 0 and 255. The highest possible difference is 255. The end result would be 0 for no slope and 256 for the highest slope.

Vivienne

1
2
3
4
5
6
7
Would this formula work?

slopex  = pixel[x+1,y] - pixel[x - 1,y];
slopey  = pixel[x,y+1] - pixel[x,y - 1];
totalslope = sqrt(slopex * slopex + slopey * slopey)*256;


Last edited on
? What do you mean by "slope"?

The only meaning of slope I can think of is to describe the angle of a line (ie: slope=0 is a flat horizontal line, slope=1 is a diagonal line going up-right, etc)

I don't understand how that applies to the colors of two pixels.
I think maybe I should say inclination difference between two points.

@Disch: think of gradient (well, modulus of gradient) http://en.wikipedia.org/wiki/Gradient
the grayscale image may be representing some variable like height or temperature.

@OP: I don't understand why are you multiplying the modulus by 256
pixel is in the range [0;255] so the slope is in range [-255;255], that would make the modulus being in range [0; \sqrt{2}*255] to which you multiply by 256
Topic archived. No new replies allowed.