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

Thresholding to min(datatype) and max(datatype)

Ladislav_K_
Beginner
805 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
805 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

0 Kudos
10 Replies
Zhen_Z_Intel
Employee
805 Views

Hi Ladislav,

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

Best regards,
Fiona

0 Kudos
Zhen_Z_Intel
Employee
805 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

0 Kudos
Ladislav_K_
Beginner
805 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 ?

0 Kudos
Zhen_Z_Intel
Employee
805 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

0 Kudos
Ladislav_K_
Beginner
805 Views

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

0 Kudos
SergeyKostrov
Valued Contributor II
805 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.
0 Kudos
Ladislav_K_
Beginner
805 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.

0 Kudos
gast128
Beginner
805 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.

0 Kudos
Adriaan_van_Os
New Contributor I
806 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

 

0 Kudos
Ladislav_K_
Beginner
805 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);

0 Kudos
Reply