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 9151005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:41:44+00:00 2026-06-17T11:41:44+00:00

I’ve just tested Sobel using C api and C++ api. But why is it

  • 0

I’ve just tested Sobel using C api and C++ api. But why is it different? All the parameters I used are the same.

Sobel using C API Output – using C API

Sobel using C++ API Output – using C++ API

Edited

C API :

/// Generate grad_x
grad_x = cvCreateImage(cvGetSize(grayImg), IPL_DEPTH_16S, 1);
abs_grad_x = cvCreateImage(cvGetSize(grayImg), 8, 1);

/// Gradient X
cvSobel(grayImg, grad_x, 1, 0, 3);
cvConvertScaleAbs(grad_x, abs_grad_x);
cvThreshold(abs_grad_x, abs_grad_x, 0, 255, CV_THRESH_BINARY|CV_THRESH_OTSU);

C++ API :

cv::Mat img_sobel;
cv::Sobel(img_gray, img_sobel, CV_8U, 1, 0, 3, 1, 0, BORDER_DEFAULT);

Mat img_threshold;
threshold(img_sobel, img_threshold, 0, 255, CV_THRESH_OTSU+CV_THRESH_BINARY);
  • 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-17T11:41:45+00:00Added an answer on June 17, 2026 at 11:41 am

    There is only 1 reason for different results. Data-Type!

    In the C version, you are creating grad_x with IPL_DEPTH_16S depth. So each pixel has short data type. This increases the precision of the results which you get when calling the cvSobel function. cvSobel is able to accommodate a wider range of values (-32768 to 32767) in the result grad_x.

    In the C++ version, you are not initializing the matrix and specifying the destination type CV_8U. The function cv::Sobel internally creates destination matrix of type CV_8U, calculates the results and then clamps them to the range of destination data type, i.e from 0 to 255. So all the negative values become 0.

    To get the same results in C version, change the IPL_DEPTH_16S to IPL_DEPTH_8U.

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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 using JSon response to parse title,date content and thumbnail images and place
I used javascript for loading a picture on my website depending on which small
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.