How To?: Sobel Filter on image

edited December 2017 in Questions about Code

I searched a lot but didn't find anything about the sobel filter for Processing. My task is to use the sobel filter on a normal colored image. I think I understood the sobel filter method, but I have absolutely no clue how to set that in code.

I can use the 2 kernels for 2 direction and iterate them over the whole image, to detect the pixels, which are inbetween e.g. a black and a white pixel. I can calculate the gradient magnitude with these results. And it's also possible to calculate the gradient's direction (But I think that's unnecessary for me).

So now I have these kernels for the x- and the y-direction...

    float filterx[][] = {
    {-1, 0, 1}, 
    {-2, 0, 2}, 
    {-1, 0, 1}};

    float filtery[][] = {
    {-1, -2, -1}, 
    {0, 0, 0}, 
    {1, 2, 1}};

and now I should iterate them over the whole image, with 2 for-loops(?)

and with the following one, I can calculate the gradient magnitude.

float gradientengroeße = sqrt(pow(gx, 2), pow(gy, 2));

But I have to get gx and gy somehow. And do I have to do these steps 3 times (for red, green, blue)? Or how should I start with that? And how do I iterate a two-dimensional Array over the image? I'm super confused, can someone help me :/



Sign In or Register to comment.