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!
6594 Discussions

Thresholding to min(datatype) and max(datatype)

Ladislav_K_
Beginner
230 Views

Hi,
it is often needed to threshold image from gray colors to black/white. There are many Threshold functions, but I can not find any which is able to do it.
For example we have 1 channel image with Ipp8u pixel size. I want do:
  if [pixel] <= threshold then set it to lowValue else set it to hiValue

There is: Threshold_LTValGTVal which allows me specify two thresholds and two values, but conditions are LT and GT so when I use:
  ippiThreshold_LTValGTVal_8u_C1IR(pSrcDst, srcDstStep, roiSize, 127, 0, 127, 255)
Pixels with value 127 remain unchanged, does not ?
And according to documentation I can not specify thresholdLT (128) > thresholdGT (127)

So is there any workaround or do you plan introduce new function ?

0 Kudos
1 Solution
Adriaan_van_Os
New Contributor I
230 Views

You can use ippiCompareC to threshold to a black-and white mask. Note that the destination mask will be of type 8u, even if the source image has type 16u or 32f.

For more complicated thresholding operations of 8u or 16u images, you can also consider using ippiLUTPalette.

Regards,

Adriaan van Os

 

View solution in original post

10 Replies
Zhen_Z_Intel
Employee
230 Views

Hi Ladislav,

It is real a problem as you said. I will submit to our developer team. Thanks.

Best regards,
Fiona

Zhen_Z_Intel
Employee
230 Views

Hi Ladislav,

If you just intend to realize the binarization but do not care about the data type or image mode, you could refer the convert function ippiGrayToBin. However the output is 1u for binary data not 8u. 

Best regards,
Fiona

Ladislav_K_
Beginner
230 Views

Hi Fiona,

thank you for your comments. I am aware of GrayToBin function, but it is not usable in my case. I need in-place thresholding of 8u image as I wrote:   if [pixel] <= threshold then set it to lowValue else set it to hiValue
(or simplified: if [pixel] <=127 then set it to 0 else set it to 255)

I think that it is very common scenario used in binarization of gray scaled images, does not ?

Do you think that developement team will provide any feedback ?

Zhen_Z_Intel
Employee
230 Views

Hi Ladislav,

I already submitted your feature request, we will consider it. Right now, the simplest solution is to call Threshold_LTVal and Threshold_GTVal separately to realize the functionality.

Best regards,
Fiona

Ladislav_K_
Beginner
230 Views

Thank you Fiona,
For now I did it as you recommended. Please let me know if you decide implement this feature request.

SergeyKostrov
Valued Contributor II
230 Views
>>...So is there any workaround or do you plan introduce new function? You can convert an image with 8-bit dynamic range to an image of wider dynamic range and I don't think that a new function in IPP is needed.
Ladislav_K_
Beginner
230 Views

@Sergey: but I do not need wider range. I need threshold grayscaled 8u image with 256 possible values per each pixel to 0 (black) or 255 (white). There is function: ippiThreshold_LTValGTVal_8u_C1IR, but it cannot be used as explained above.

So only workaround for now is use two calls:
                  ippiThreshold_LTVal_8u_C1IR(pSrcDst, srcDstStep, roiSize, AThreshold+1, 0);
                  ippiThreshold_GTVal_8u_C1IR(pSrcDst, srcDstStep, roiSizei, AThreshold, 255);
Which seems to me not so efficient as one call would be.

gast128
Beginner
230 Views

Needed here as well: threshold a grey (u8) image with px = px < threshold ? 0 : 255; etc. Now this has to be done in two steps with IPP which is a performance drawback.

Adriaan_van_Os
New Contributor I
231 Views

You can use ippiCompareC to threshold to a black-and white mask. Note that the destination mask will be of type 8u, even if the source image has type 16u or 32f.

For more complicated thresholding operations of 8u or 16u images, you can also consider using ippiLUTPalette.

Regards,

Adriaan van Os

 

View solution in original post

Ladislav_K_
Beginner
230 Views

Yes ippiCompareC works as expected. Thank you. I can use it also as in-line (Src=Dst):

  ippiCompareC_8u_C1R(Src, Width, AThreshold, Src, Width, roiSize, ippCmpGreaterEq);

Reply