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

Binarizing an image via thresholding

monarckmills
Beginner
2,112 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
2,112 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

 

0 Kudos
Adriaan_van_Os
New Contributor I
2,112 Views

And in this specific case you could also try ippiReduceBits.

Regards,

Adriaan van Os

 

0 Kudos
Igor_A_Intel
Employee
2,112 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

 

0 Kudos
Igor_A_Intel
Employee
2,112 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

0 Kudos
Adriaan_van_Os
New Contributor I
2,112 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

0 Kudos
monarckmills
Beginner
2,112 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.

0 Kudos
Igor_A_Intel
Employee
2,112 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

0 Kudos
Reply