0
$\begingroup$

I am trying to implement a sobel filter to locate horizontal edges in a 160x120 pixel image that is captured from a OV7725 CMOS camera module that outputs RGB565 data.

I've done the RGB565 -> 8-bit grayscale conversion as can be seen in the first pictureRGB565 to 8-bit grayscale

However, when I try to do my sobel operation on the grayscale picture it gets a bit funky and the output is multiplied for some reason. I've been looking at my implementation but can't seem to find out what is wrong...

Filtered grayscale iamge

Below is my implementation in C and I don't really care about the pixel at the edges.

void sobelFilter(int8_t *inputImg, int8_t *outputImg)
{
    uint16_t row;
    uint16_t col;
    uint16_t pos;

    int16_t pixel_x;
    int16_t pixel_y;

    const int8_t sobel_h[3][3] = {
            {-1, 0, 1},
            {-2, 0, 2},
            {-1, 0, 1}
    };

    for (row = 1; row < 120 - 1; row++)
    {
        for (col = 1; col < 160 - 1; col++)
        {
            pos = 120 * row + col;

            pixel_x = inputImg[pos - 121] * sobel_h[0][0];
            pixel_x += inputImg[pos - 119] * sobel_h[0][2];

            pixel_x += inputImg[pos - 1] * sobel_h[1][0];
            pixel_x += inputImg[pos + 1] * sobel_h[1][2];

            pixel_x += inputImg[pos + 119] * sobel_h[2][0];
            pixel_x += inputImg[pos + 121] * sobel_h[2][2];

            outputImg[pos] = sqrt( (pixel_x * pixel_x) );) );
        }
    }
}

Is there something funky with my implementation that I've missed or am doing wrong? Like why is it producing 3 copies of the "object" and why is the filtered image not being filtered the whole way down?

$\endgroup$
  • $\begingroup$ The reason why it was not going through the whole picture was because one line was wrong, it position should be pos = 120 * col + row; However, no idea why its producing multiple outputs :S $\endgroup$ – Pethead May 11 '17 at 11:12
1
$\begingroup$

I solved it by using a threshold value for the pixel value that I got from sqrt( (pixel_x * pixel_x) );enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.