OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 07 Feb 2013 09:28:12 -0600Sobel function argumenthttp://answers.opencv.org/question/7037/sobel-function-argument/Hi All,
Im new to OpenCV and I'm trying for the past hour to understand what is the scale and delta input argument to cv::Sober function.
Can anyone help me?
Thank u in advanceWed, 06 Feb 2013 16:26:30 -0600http://answers.opencv.org/question/7037/sobel-function-argument/Answer by Michael Burdinov for <p>Hi All,</p>
<p>Im new to OpenCV and I'm trying for the past hour to understand what is the scale and delta input argument to cv::Sober function. </p>
<p>Can anyone help me?</p>
<p>Thank u in advance</p>
http://answers.opencv.org/question/7037/sobel-function-argument/?answer=7047#post-id-7047[Documentation](http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=sobel#sobel) of Sobel function is prety clear on this:
"scale – optional scale factor for the computed derivative values; by default, no scaling is applied."
"delta – optional delta value that is added to the results prior to storing them in dst."
The reason why those arguments are part of the function is that type of image that stores the derivative may not be enough for whole range of values. For example: assume you are calculating derivative of CV_8U image with default kernel size. Resulting values of derivatives will be in range between -1024 and 1024. You may want (for various reasons) to stores derivatives in image of the same type, i.e. CV_8U. This means that all negative values will be cropped to 0, and all values above 255 will be cropped to 255. To pervent this crop you may set scale to 0.125 and delta to 128, so that all results will fall in range between 0 and 255.Thu, 07 Feb 2013 01:02:51 -0600http://answers.opencv.org/question/7037/sobel-function-argument/?answer=7047#post-id-7047Comment by eyal for <p><a href="http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=sobel#sobel">Documentation</a> of Sobel function is prety clear on this:</p>
<p>"scale – optional scale factor for the computed derivative values; by default, no scaling is applied."</p>
<p>"delta – optional delta value that is added to the results prior to storing them in dst."</p>
<p>The reason why those arguments are part of the function is that type of image that stores the derivative may not be enough for whole range of values. For example: assume you are calculating derivative of CV_8U image with default kernel size. Resulting values of derivatives will be in range between -1024 and 1024. You may want (for various reasons) to stores derivatives in image of the same type, i.e. CV_8U. This means that all negative values will be cropped to 0, and all values above 255 will be cropped to 255. To pervent this crop you may set scale to 0.125 and delta to 128, so that all results will fall in range between 0 and 255.</p>
http://answers.opencv.org/question/7037/sobel-function-argument/?comment=7067#post-id-7067First of all thank u very much for your answer!!
now I see why scale and delta are needed. But how do I know the output ranges if the derivatives I mean how do u know that derivatives of CV_8U map to [-1024,1024] ??
Thu, 07 Feb 2013 07:29:32 -0600http://answers.opencv.org/question/7037/sobel-function-argument/?comment=7067#post-id-7067Comment by Michael Burdinov for <p><a href="http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=sobel#sobel">Documentation</a> of Sobel function is prety clear on this:</p>
<p>"scale – optional scale factor for the computed derivative values; by default, no scaling is applied."</p>
<p>"delta – optional delta value that is added to the results prior to storing them in dst."</p>
<p>The reason why those arguments are part of the function is that type of image that stores the derivative may not be enough for whole range of values. For example: assume you are calculating derivative of CV_8U image with default kernel size. Resulting values of derivatives will be in range between -1024 and 1024. You may want (for various reasons) to stores derivatives in image of the same type, i.e. CV_8U. This means that all negative values will be cropped to 0, and all values above 255 will be cropped to 255. To pervent this crop you may set scale to 0.125 and delta to 128, so that all results will fall in range between 0 and 255.</p>
http://answers.opencv.org/question/7037/sobel-function-argument/?comment=7070#post-id-7070You should check the kernel that is used. 3x3 Sobel kernel is [[-1, -2, -1], [0, 0, 0], [1, 2, 1]]. Maximum value for it will be 1 * 255 + 2 * 255 + 1 * 255 = 1020. And minimum value is -1 * 255 - 2 * 255 - 1 * 255 = - 1020.Thu, 07 Feb 2013 07:52:53 -0600http://answers.opencv.org/question/7037/sobel-function-argument/?comment=7070#post-id-7070Comment by eyal for <p><a href="http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=sobel#sobel">Documentation</a> of Sobel function is prety clear on this:</p>
<p>"scale – optional scale factor for the computed derivative values; by default, no scaling is applied."</p>
<p>"delta – optional delta value that is added to the results prior to storing them in dst."</p>
<p>The reason why those arguments are part of the function is that type of image that stores the derivative may not be enough for whole range of values. For example: assume you are calculating derivative of CV_8U image with default kernel size. Resulting values of derivatives will be in range between -1024 and 1024. You may want (for various reasons) to stores derivatives in image of the same type, i.e. CV_8U. This means that all negative values will be cropped to 0, and all values above 255 will be cropped to 255. To pervent this crop you may set scale to 0.125 and delta to 128, so that all results will fall in range between 0 and 255.</p>
http://answers.opencv.org/question/7037/sobel-function-argument/?comment=7078#post-id-7078I see...Thank u , you the best :)Thu, 07 Feb 2013 09:28:12 -0600http://answers.opencv.org/question/7037/sobel-function-argument/?comment=7078#post-id-7078