Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Nickolas_G_
Beginner
77 Views

ColorConvert16s trouble

I am trying to call ippiColorToGray_16s_C3C1R and have a strange results. For typical image in range 0 - 255 (but in 16s) and standard coeffs i get pixels with value below -10000.

Finding the reason, I tried to call this func with  different input. e.g. with zero coeffs, with only one non-zero coeff and with only-one-pixel image (1x1)

With zero coeffs, result is 16s min (-32,768, 0 expected) so it makes me think about unsigned result - but in docs it says that Dst type is similar to Src. So, can anyone resolve my doubts? Is it bug or what?

 

UPD: Works fine if coeffs sum is equal to 1. If it less - as said above

 

Regards

Nickolas

0 Kudos
5 Replies
Sergey_P_Intel1
Employee
77 Views

To answer question send me your code,pls.

Sergey.

Nickolas_G_
Beginner
77 Views

Good day, Sergey! Thx for your answer.

Here is not my code, but this sample app gives a nice presentation of this (bug?)

//

#include <iostream>

#include <ipp.h>
using namespace std;

void printImage(Ipp16s* pSrc, int width, int height, int srcStep, int chan)
{
   for (int y = 0; y < height; y++)
   {
      cout << "[";
      for (int x = 0; x < width; x++)
      {
         cout << "{";
         for (int c = 0; c < chan; c++)
         {
            Ipp8u * ptr = (Ipp8u *)pSrc;
            ptr += srcStep * y + x * chan * sizeof(Ipp16s) + c * sizeof(Ipp16s);

            Ipp16s val = *(Ipp16s *)ptr;
            cout << " " << val << ",";
         }
         cout << "}";
      }
      cout << "]" << endl;
   }
}

int main()
{
   int width = 5;
   int height = 5;

   int srcStep = 0;
   int dstStep = 0;
   IppiSize roi = {width, height};
   Ipp32f coeff[3] = {0.1, 0.1, 0.1};
   Ipp16s* pSrc = ippiMalloc_16s_C3(width, height, &srcStep);

   Ipp16s startVal[3] = {5, 5, 5};
   ippiSet_16s_C3R(startVal, pSrc, srcStep, roi);

   Ipp16s* pDst = ippiMalloc_16s_C1(width, height, &dstStep);

   ippiColorToGray_16s_C3C1R(pSrc, srcStep, pDst, dstStep, roi, coeff);

   printImage(pSrc, width, height, srcStep, 3);
   cout << endl;
   printImage(pDst, width, height, dstStep, 1);

   return 0;
}


//

with this coeffs, out is this:

SRC:

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

DST:

[{ -22936,}{ -22936,}{ -22936,}{ -22936,}{ -22936,}]

[{ -22936,}{ -22936,}{ -22936,}{ -22936,}{ -22936,}]

[{ -22936,}{ -22936,}{ -22936,}{ -22936,}{ -22936,}]

[{ -22936,}{ -22936,}{ -22936,}{ -22936,}{ -22936,}]

[{ -22936,}{ -22936,}{ -22936,}{ -22936,}{ -22936,}]

 

But if i change coeffs to Ipp32f coeff[3] = {0.1, 0.8, 0.1}; (sum eqals to 1), out is

SRC:

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

[{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}{ 5, 5, 5,}]

DST:

[{ 5,}{ 5,}{ 5,}{ 5,}{ 5,}]

[{ 5,}{ 5,}{ 5,}{ 5,}{ 5,}]

[{ 5,}{ 5,}{ 5,}{ 5,}{ 5,}]

[{ 5,}{ 5,}{ 5,}{ 5,}{ 5,}]

[{ 5,}{ 5,}{ 5,}{ 5,}{ 5,}]

 

Which is right. What's the problem?

Sergey_P_Intel1
Employee
77 Views

All color functions RGB_16s<>Color_16s/HSV_16s … work so.

E.g.:

R = (float)(src[0] + 32768); G = (float)(src[1] + 32768); B = (float)(src[2] + 32768);

gray = (Ipp16s) (k0 * R + k1 * G + k2 * B) - 32768);

Regards,

Sergey.

Nickolas_G_
Beginner
77 Views

But... Why so? It seems not as right behaviour, as I understand, isn't it?

ILevi1
Valued Contributor I
77 Views

First, if you don't need to specify your color coefficients you should use ippiRGBToGray() which uses standard coefficients.

Second, ColorToGray() works like this:

Y = coeffs[0] * R + coeffs[1] * G + coeffs[2] * B;
Sum of coeffs must be positive and <= 1. Thrid, what he wrote above is that temporary bias of 32768 is being added to avoid negative values for R, G, and B. Hope this helps.
Reply