Change color value of pixels

Change color value of pixels

Аватар пользователя Aditya Kadambi

I am looking for a function to do selective change of colors in an image.

I have a RGB 32 image. It basically is white text with black back. I am looking for IPP function or set of functions that can accomplish this:

1. I will provide pixel treshlold for color change. Basically the treshold value is 0xFF (white). Hence say 0xFFFFFF.

2. Now, having provided this value, change the color of all pixels that match 0xFF to any other value I want to.

How can I accomplish this with IPPI library?

10 сообщений / 0 новое
Последнее сообщение
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.
Аватар пользователя Aditya Kadambi

Well, this is as simple as using the threshold functions ippiThreshold<> !!

Аватар пользователя Sergey Khlystov (Intel)

Hi Aditya,

Look at ippiLUT functions if you can do anything with them.

Regards,
Sergey 

Regards, Sergey
Аватар пользователя Aditya Kadambi

Thank you Segey.

For my issue, the threshold functions worked like a charm!

Аватар пользователя Aditya Kadambi

Hi Sergey;

Actually I need something like LUT, right you are.

Here is the actual problem I am trying to solve.

I have an image which has any kinds of colors. I want all of them to "fade to" black. So, this is a per pixel operation.

So, in a loop, I will be doing this:

color_value[idx] = color_value[idx] - decreament_value.

This way each color value in the image decreases and tends to zero eventually. What is the best way to accomplish this?

Аватар пользователя Sergey Khlystov (Intel)

Hi Aditya,

I would use ippiLUT_8u_C3R function with pValues and pLevels as { {0, 1, ..., 255}, {0, 1, ..., 255}, {0, 1, ..., 255} } and then in the loop gradually would decrement them by "decrement_value" until they become 0. If you want "fading" you must call ippiLUT function in each loop iteration. Though, it can be another method. You can use function ippiSubC for that. On Ipp8u data it has saturation effect, i.e. data values will not become less than 0 (in unsigned world it means 0-1=255), so the colors will not be bright again. Check this.

Regards,
Sergey 

Regards, Sergey
Аватар пользователя Aditya Kadambi

Hi Sergey;

Thank you very much. Looks like ippiSubC will definitely accomplish what I need. Let me try that and report back.

Аватар пользователя Aditya Kadambi

Hi Sergey;

The ippiSubC does cause the image to get "bright" in the loop due to the reason you mentioned.

LUT approach seems to be best one. However, I have not seen an example of the usage. This is how I am setting up the values for the function:

Ipp8u rValues[256], gValues[256], bValues[256], aValues[256];
Ipp8u rLevels[256], gLevels[256], bLevels[256], aLevels[256];

    for (int vdx = 0; vdx < 256; ++ vdx) {
        rValues[vdx] = vdx;
        gValues[vdx] = vdx;
        bValues[vdx] = vdx;
        aValues[vdx] = 0;
        rLevels[vdx] = vdx;
        gLevels[vdx] = vdx;
        bLevels[vdx] = vdx;
        aLevels[vdx] = 0;
    }

Ipp8u * colorValues[4] = {rValues, gValues, bValues, aValues};
Ipp8u * colorLevels[4] = {rLevels, gLevels, bLevels, aLevels};
int nColorLevels[4];

status = ippiLUT_8u_AC4R(src, srcStrp, dst, dstStep, ROISize, (const Ipp32s **)colorValues, (const Ipp32s **)colorLevels, nColorLevels);

I am not yet clear on what nColorLevels is. How will this achieve the fading effect.

I guess my question is, I am not clear on the usage of the LUT function.

Аватар пользователя Sergey Khlystov (Intel)

Hi Aditya,

It mustn't be so (I mean SubC). Look at the test below:

Ipp8u testImage[] = {
6, 6, 6, 6,
6, 6, 6, 6,
6, 6, 6, 6,
6, 6, 6, 6
};
const Ipp8u subVal[3] = { 2, 2, 2 };
int main()
{
   int i, j;
   IppiSize roiSize = { 4, 4 };
   ippInit();
   for(i=0; i < 10; i++) {
      ippiSubC_8u_AC4IRSfs(subVal, testImage, 4, roiSize, 0);
      printf("Step: %d Image=", i+1);
      for(j = 0; j <sizeof(testImage); j++)
         printf("%d ", testImage[j]);
      printf("n");
   }
}
 

It generates:
Step: 1 Image=4 4 4 6 2 2 2 6 0 0 0 6 0 0 0 6
Step: 2 Image=2 2 2 6 0 0 0 6 0 0 0 6 0 0 0 6
Step: 3 Image=0 0 0 6 0 0 0 6 0 0 0 6 0 0 0 6
Step: 4 Image=0 0 0 6 0 0 0 6 0 0 0 6 0 0 0 6
Step: 5 Image=0 0 0 6 0 0 0 6 0 0 0 6 0 0 0 6
Step: 6 Image=0 0 0 6 0 0 0 6 0 0 0 6 0 0 0 6
Step: 7 Image=0 0 0 6 0 0 0 6 0 0 0 6 0 0 0 6
Step: 8 Image=0 0 0 6 0 0 0 6 0 0 0 6 0 0 0 6
Step: 9 Image=0 0 0 6 0 0 0 6 0 0 0 6 0 0 0 6
Step: 10 Image=0 0 0 6 0 0 0 6 0 0 0 6 0 0 0 6

Isn't it what you wanted?

Regards,
Sergey 

Regards, Sergey
Аватар пользователя Aditya Kadambi

Hi Sergey;

Yes, you are right. I looked into my code again. I am not using in place SubC function.

This is what I was doing wrong:

I had set the SubVal[] to be {2, 2, 2} (or say some other value). Because my SubC function was not inplace change, I had to increament this SubVal in my loop so that the color faded during each loop:

This way

dst = src - SubVal;

dst = src - (SubVal + increament)

... and so on.

At some point (SubVal + increament) went over 255 (you had warned about this) and hence it became 0.

Hence

dst = src - 0

This caused the issue.

I fixed the issue. Thank you so much for your help.

Зарегистрируйтесь, чтобы оставить комментарий.