Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:24:29+00:00 2026-06-14T12:24:29+00:00

I’m having a problem with edge detection using Sobel operator: it produces too many

  • 0

I’m having a problem with edge detection using Sobel operator: it produces too many false edges, effect is shown on pictures below.
I’m using a 3×3 sobel operator – first extracting vertical then horizontal, final output is magnitude of each filter output.
Edges on synthetic images are extracted properly but natural images produce have too many false edges or “noise” even if image is preprocessed by applying blur or median filter.
What might be cause of this? Is it implementation problem (then: why synthetic images are fine?) or I need to do some more preprocessing?

Original:
orig

Output:
out

code:

void imageOp::filter(image8* image, int maskSize, int16_t *mask)
{
    if((image == NULL) || (maskSize/2 == 0) || maskSize < 1)
    {
        if(image == NULL)
        {
            printf("filter: image pointer == NULL \n");
        }
        else if(maskSize < 1)
        {
            printf("filter: maskSize must be greater than 1\n");
        }
        else
        {
            printf("filter: maskSize must be odd number\n");
        }
        return;
    }

    image8* fImage = new image8(image->getHeight(), image->getWidth());
    uint16_t sum = 0;
    int d = maskSize/2;
    int ty, tx;

    for(int x = 0; x < image->getHeight(); x++)         //
    {                                                   // loop over image
        for(int y = 0; y < image->getWidth(); y++)      // 
        {
            for(int xm = -d; xm <= d; xm++)
            {
                for(int ym = -d; ym <= d; ym++)
                {
                    ty = y + ym;
                    if(ty < 0)  // edge conditions
                    {
                        ty = (-1)*ym - 1;
                    }
                    else if(ty >= image->getWidth())
                    {
                        ty = image->getWidth() - ym;
                    }

                    tx = x + xm;
                    if(tx < 0)  // edge conditions
                    {
                        tx = (-1)*xm - 1;
                    }
                    else if(tx >= image->getHeight())
                    {
                        tx = image->getHeight() - xm;
                    }

                    sum += image->img[tx][ty] * mask[((xm+d)*maskSize) + ym + d];
                }
            }

            if(sum > 255)
            {
                fImage->img[x][y] = 255;
            }
            else if(sum < 0)
            {
                fImage->img[x][y] = 0;
            }
            else
            {
                fImage->img[x][y] = (uint8_t)sum;
            }
            sum = 0;
        }
    }


    for(int x = 0; x < image->getHeight(); x++)
    {
        for(int y = 0; y < image->getWidth(); y++)
        {
            image->img[x][y] = fImage->img[x][y];
        }
    }

    delete fImage;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:24:30+00:00Added an answer on June 14, 2026 at 12:24 pm

    This appears to be due to a math error somewhere in your code. To follow on my comment, this is what I get when I run your image through a Sobel operator here (edge strength is indicated by brightness of the output image):

    Image after Sobel operator

    I used a GLSL fragment shader to produce this:

     precision mediump float;
    
     varying vec2 textureCoordinate;
     varying vec2 leftTextureCoordinate;
     varying vec2 rightTextureCoordinate;
    
     varying vec2 topTextureCoordinate;
     varying vec2 topLeftTextureCoordinate;
     varying vec2 topRightTextureCoordinate;
    
     varying vec2 bottomTextureCoordinate;
     varying vec2 bottomLeftTextureCoordinate;
     varying vec2 bottomRightTextureCoordinate;
    
     uniform sampler2D inputImageTexture;
    
     void main()
     {
        float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;
        float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;
        float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;
        float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;
        float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;
        float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;
        float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;
        float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;
        float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
        float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;
    
        float mag = length(vec2(h, v));
    
        gl_FragColor = vec4(vec3(mag), 1.0);
    

    You don’t show your mask values, which I assume contain the Sobel kernel. In the above code, I’ve hardcoded the calculations performed against the red channel of each pixel in a 3×3 Sobel kernel. This is purely for performance on my platform.

    One thing I don’t notice in your code (again, I may be missing it like I did the sum being set back to 0) is the determination of the magnitude of the vector for the two portions of the Sobel operator. I’d expect to see a square root operation in there somewhere, if that was present.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.