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

## Compare with result 1 or 0

Beginner
382 Views
Hello,

I would like to count the number of pixels in a neighborhood for which a certain condition is true.

The idea is that I use ippiCompare to find those pixels for which the condition is true and then use ippiSumWindowRow and ippiSumWindowColumn to basically add all the pixels that are not zero.

In Matlab this is easy as the compare operation delivers a 1 for the true condition. A filter with a box kernel then does the trick. As the kernel is 11x11 in size, it can never overflow even uint8 images. However in the ippi library the compare operation delivers a result of 255 for the true conditions. I would first have to shift the pixels by seven bits to the right to get ones.

Alternatively, I could misuse the Threshold_LTValGTVal function to ensure that I only get zeros and ones.

Is there a better and more efficient way?

Best regards,
Marcus
4 Replies
Valued Contributor II
382 Views
>>...I use ippiCompare to find those pixels for which the condition is true...

You're comparing withsome value, right? A threshold, for example.

>>...However in the ippi library the compare operation delivers a result of 255 for the true conditions...

All ippiCompare_ functionsreturn IppStatus value and if a condition is true it has to be
equal to ippStsNoErr ( Ok ), that is 0. It is not clear how ippiComparereturns 255?

Could you post a Test-Case that reproduces the problem?

Best regards,
Sergey
Beginner
382 Views
Hi Sergey,

thanks for your quick reply. However, I think you misunderstood my question.

The ippiCompare functions do a pixel-by-pixel compare of the source image with a threshold or with another image. The result of this compare is a destination image where the pixels of that image are set to 0 if the compare is false or 255 if the compare is true. What I need however is for those pixels where the comparison is true to be 1.

This isn't a bug, the library works as specified. However, I need to know for each pixel in the image, for how many pixels in its neighborhood the condition is true. If those pixels where the condition is true were set to 1 I only needed to do a simple filtering operation.

Best regards,
Marcus
New Contributor II
382 Views
Hi Marcus,

ippiFilterBox_8u will not overflow for all pixels=255 as it performs intermediate calculations in 32s (running sum algorithm is used) and then performsnormalization on thekernel size - so output is divided by 121 in your case.

Regards,
Igor
Beginner
382 Views
Hi Igor,
yes, it might be possible to use ippiFilterBox. The result of ippiCompare is 255 where it is true and thus, the result of ippiFilterBox will be the number of pixels times 255 divided by the area of the kernel, which is 121 in my case. Thus, to get the real number I would have to multiply with 121 and divide by 255.
As it turns out, I can move around some of the later computations such that I can avoid having to actually perform that multiply and divide.