Intel® Integrated Performance Primitives
Community support and discussions relating to developing high-performance vision, signal, security, and storage applications.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Binarizing an image via thresholding

monarckmills
Beginner
497 Views

Hi, the search function is messed up and unusable, so I am creating a new topic without being able to search for a similar thread.

 I want to simply binarize a 8bit single channel (gray) image with a threshold. Eg. pixels >= 128 will be set to 255, other pixels (which are <  128) will be set to 0.

None of the ipp thresholding functions seem to work for this. Closest one is Threshold_LTValGTVal which does not accept 128 and 127 as the thresholdLT and thresholdGT values. It says thresholdGT must be >= thresholdLT, which leaves the pixels equal to the threshold as is, if I set both of them to 128.

I believe binarizing an image over a single threshold is a very common operation and I don't want to to aritmetic operations or thresholding twice to achive such a simple task. What am I missing?

 

Update: the reason i dont want to use arithmetic operations, eg. divide by 128 to binarize is :

uint8_t testimg[8] = {1, 126, 127, 128, 129, 139, 254, 255};
uint8_t testout[8] = {0};

ippiDivC_8u_C1RSfs(testimg, 8, 128, testout, 8, IppiSize{8, 1}, 0);

// testout: [0 1 1 1 1 1 2 2]

 

0 Kudos
7 Replies
Adriaan_van_Os
New Contributor I
497 Views

Yes, I have stumbled over the limitations of the IPP threshold functions too. But for 8u and 16u, the alternative is to use ippiLUTPalette.

Regards,

Adriaan van Os

 

Adriaan_van_Os
New Contributor I
497 Views

And in this specific case you could also try ippiReduceBits.

Regards,

Adriaan van Os

 

Igor_A_Intel
Employee
497 Views

Hi Adriaan van Os,

IppStatus ippiCompare_<mod>(const Ipp<datatype>* pSrc1, int src1Step, const
Ipp<datatype>* pSrc2, int src2Step, Ipp8u* pDst, int dstStep, IppiSize roiSize,
IppCmpOp ippCmpOp);
Supported values for mod:
8u_C1R 16u_C1R 16s_C1R 32f_C1R
8u_C3R 16u_C3R 16s_C3R 32f_C3R
8u_C4R 16u_C4R 16s_C4R 32f_C4R

 

This function compares the corresponding pixels of ROI in two source images pSrc1, pSrc2 using the
ippCmpOp compare operation, and writes the results to a one-channel Ipp8u image pDst. If the result of the
compare is true, the corresponding output pixel is set to an IPP_MAX_8U value; otherwise, it is set to 0.

regards, Igor

 

Igor_A_Intel
Employee
497 Views

Sorry, copy-pasted wrong reference - you should use compare operation with const value:

IPPAPI (IppStatus, ippiCompareC_8u_C1R,(const Ipp8u* pSrc, int srcStep, Ipp8u value,

                                              Ipp8u* pDst, int dstStep,

                                        IppiSize roiSize,  IppCmpOp ippCmpOp))

regards, Igor

Adriaan_van_Os
New Contributor I
497 Views

Igor,

Yes, thanks, that works in the example case given above.

But now for another example. Suppose I have two threshold values A and B where A <= B, Suppose I want to give all pixels where pixel =< A or pixel >= B a specific value. I call ippiThreshold_LTValGTVal. So far, so good. But what IPP function to call if I want to give all pixels where A < pixel < B a specific value ?

Regards,

Adriaan van Os

monarckmills
Beginner
497 Views

Igor Astakhov (Intel) wrote:

Sorry, copy-pasted wrong reference - you should use compare operation with const value:

IPPAPI (IppStatus, ippiCompareC_8u_C1R,(const Ipp8u* pSrc, int srcStep, Ipp8u value,

                                              Ipp8u* pDst, int dstStep,

                                        IppiSize roiSize,  IppCmpOp ippCmpOp))

regards, Igor

 

Hi Igor, thank you! This is what I was missing.

Igor_A_Intel
Employee
497 Views

Hi Adriaan van Os,

regarding Threshold_LTValGTVal - for your use case there should be developed one more API - something like Threshold_LTValGEVal. We'll consider this new API for future versions.

regards, Igor

Reply