Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Sobel Filters

rogene
Beginner
606 Views
Hello,

I have an Ipp8u* ippImage that I read in from a bitmap file. After passing the ippImage through the Sobel filters, I get Ipp16s* images dx and dy. However, they look nothing like the gradient from the original image.

After reading a few other forum entries, I am confused whether I should be adding/subtracting border pixels. Or whether I should be adding an offset to my source image. Would someone kindly look at the following code and tell me where I am going wrong? Thanks!

[cpp]// get sizes needed and allocate buffers
IppiSize roi = {width, height};  // based on ippImage dimensions[/cpp]
[cpp]int nvsize, hsize;
ippiFilterSobelNegVertGetBufferSize_8u16s_C1R(roi,ippMskSize3x3, &nvsize);
ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roi,ippMskSize3x3, &hsize);
Ipp8u *nvbuffer = ippsMalloc_8u(nvsize);
Ipp8u *hbuffer = ippsMalloc_8u(hsize);

// process sorbel filters
int dxstride, dystride;
Ipp16s *dx = ippiMalloc_16s_C1(width, height, &dxstride);
Ipp16s *dy = ippiMalloc_16s_C1(width, height, &dystride);
IppiSize sroi = {width, height};
ippiFilterSobelNegVertBorder_8u16s_C1R(this->ippImage, stride, dx, dxstride, sroi, ippMskSize3x3, ippBorderRepl, 0, nvbuffer);
ippiFilterSobelHorizBorder_8u16s_C1R(this->ippImage, stride, dy, dystride, sroi, ippMskSize3x3, ippBorderRepl, 0, hbuffer);
[/cpp]


0 Kudos
8 Replies
Vladimir_Dudnik
Employee
606 Views
Hello,

I would recommend you to take a look at picnic application (it is part of IPP image-codecs UIC sample) where we provide IPP implementation of sobel filter.

Another opportunity is to try a new Intel Deferred Mode Image Processing layer which we built on top of IPP. In the DMIP sample (which is part of IPP image-processing samples)you will find simple and elegant sample of implemenation sobel filter.

For example, DMIP sobel may look like

[cpp]#include "dmip.h"

Image src;
Image dst;
Kernel kv(SobelVert);
Kernel kh(SobelHoriz);

dst = Abs( To16s(src) * kh ) + Abs( To16s(src) * kv );
[/cpp]

Having this simple sobel declaration at source code level the DMIP library will optimize processing for better processor cache usageand parallelize to utilize multiple cores if available for you. All you need is just to compile this piece of code with any C++ compiler and link with DMIP library. Note that underneath DMIP use IPP libraries (they are statically linked into DMIP DLL).

Regards,
Vladimir
0 Kudos
rogene
Beginner
606 Views

Thanks for your response! ButI would prefer to keep things simple and not add yet another under-documented library to myarsenaluntil I can understand how this first one works.

Where would I find the UIC sample that you mention in your post? But more importantly, where would I find an explanation for why certain parameters are selected in the implementation?

For example, I am looking at example 14-1 in the ippi manual. (The Sobel filters are just a step towards the Canny, which is my goal.) The example doesn't show how the dx and dy images are allocated and is confusing regarding how the variable "size" should be selected to allocate the buffer (take the largest of the three?). And then, why use FilterSobelNegVert instead of FilterSobelVert as inputs to the Canny?

But back to Sobel, the threadhttp://software.intel.com/en-us/forums/showthread.php?t=52835 suggests that I need to take the border into account when allocating the size of dx and dy. And then, the thread suggests that I need to send an offset image to the Canny algorithm. Which is correct? 14.1 or the thread?

Please tell me where I can find additional documentation! And by documentation, I mean examples with explanations. Thanks!

0 Kudos
rogene
Beginner
606 Views

Here are a few images to better explain my problem. The edges, dx, and dy images look like less than half the original image was processed. The return values are all "0" indicating no problems.

Ideas??? Please!!!


Edge Image


Output from Sobel NegVert

Output from Sobel Horiz

Original Image

0 Kudos
Vladimir_Dudnik
Employee
606 Views

Well, there isdocumentationfor that 'under-documented' library and it would be quite helpful if you spent some time looking through it for IPP image and border concepts, IPP filter design and particular IPP function description.There also is a sample package (it is separate download, available after you register for IPP) where you may find a number of application which might be used as a starting point to play with IPP functions.

The 14.1 example is not implemented as complete application, its goal to demonstrate the base idea of how to use IPP functions to build Canny filter. Some knowledge on edge detection and IPP concepts is expected from the reader.

Regards,
Vladimir


0 Kudos
rogene
Beginner
606 Views

I did not mean to be offensive. 1800 pages for just the image processing libraryis considerable.

But I can assure you that I have spent considerable time with this pdf file. And in comparisonwith the documentation provided with the many other libraries I have used, I am finding the explanations lacking and working with a single large document unwieldy. This frustrationhas unfortunately leaked into my tone.

Thanks for your help.




0 Kudos
Vladimir_Dudnik
Employee
606 Views
The difference between other libraries I think is that IPP provides really low-level API andas a result'close-to-the-metal' level of performance. Of course it is more difficult to study low level API, that is why I mentionhigh-level DMIP library where programming of sobel is look like just a single line of code.

I think it might be useful download IPP Sample package.

Regarding your issue, if you can attach here your test case we will be able to help to find the root cause of the issue

Regards,
Vladimir
0 Kudos
pvonkaenel
New Contributor III
606 Views
Quoting - rogene

I did not mean to be offensive. 1800 pages for just the image processing libraryis considerable.

But I can assure you that I have spent considerable time with this pdf file. And in comparisonwith the documentation provided with the many other libraries I have used, I am finding the explanations lacking and working with a single large document unwieldy. This frustrationhas unfortunately leaked into my tone.

Thanks for your help.





I only took a quick look at the code you originally posted, but from the images you uploaded, it kind of looks like the source image stride is wrong. It looks like the source image is color. Is it planar or interleaved? If it's interleaved, you might want to extract the luma and then run the filter on that.

Peter
0 Kudos
rogene
Beginner
606 Views


That was exactly the problem. I was so caught up in thinking about how to think about bit depth and various pixel formats, that I useda rgb image as a source instead of a grayscale image. I attached the beautiful new image above!
Thank you!
0 Kudos
Reply