Search code examples
c++imageimage-processingintel-ipp

Performing threshold operation on an RGB image


I need to perform a threshold operation on an RGB image. The thresholding that I intend to do should behave as follows.

If greyscale equivalent of a pixel ( calculated as 0.299 * R' + 0.587 * G' + 0.114 * B' ) is Y, then the pixel value of the output image will be:

P = Threshold_color, if Y < threshold_value
  = (R,G,B), Original value

,where Threshold_color is an RGB color value,

I wanted to perform this operation using Intel IPP library. There I found few API's related to thresholding of images. (ippiThreshold_LTVal_8u_C3R)

But these methods seems to work only on one data point at a time. But the thresholding that I want to do depends on the combination of 3 different values (R, G, B). Is there a way to achieve this through IPP library?


Solution

  • Suggested approach:

    1. Copy the image into a greyscale image
    2. Create a binary mask 0/1 (same size as greyscale image) using the threshold
    3. Multiply this mask with the replacement color you want to generate an overlay
    4. Apply the overlay to the original image.

    Note that you're generating images of different types here: first greyscale, then black&white, and finally color images again (although in step 3 it's a monochromatic image)