Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

BGR to Lab conversion

Hi all, I wrote the code for RGB to lab color conversion for cuda by using mathematical formulae which are mentioned in the OpenCV documentation but when I compare the l ,a ,b values from the cvColor function and my cuda function, there is a difference of 5 to 15. It will be great, if you suggest me the way.

__global__ void kRgb2CIELab(PtrStepSz<uchar3> src, PtrStepSz<uchar3> dst, int width, int height) {

    int px = blockIdx.x * blockDim.x + threadIdx.x;
    int py = blockIdx.y * blockDim.y + threadIdx.y;

    if (px < width && py < height)
    {

        uchar3 nPixel = src(py, px);

        float blue = (float)nPixel.x / 255.0;
        float green = (float)nPixel.y / 255.0;
        float red = (float)nPixel.z / 255.0;

        float x = red * 0.412453 + green * 0.357580 + blue * 0.180423;
        float y = red * 0.212671 + green * 0.715160 + blue * 0.072169;
        float z = red * 0.019334 + green * 0.119193 + blue * 0.950227;

        x /= 0.950456;
        float y3 = exp(log(y) / 3.0);
        z /= 1.088754;

        float l, a, b;

        x = x > 0.008856 ? exp(log(x) / 3.0) : (7.787 * x + 16/116);
        y = y > 0.008856 ? y3 : 7.787 * y + 16/116;
        z = z > 0.008856 ? z /= exp(log(z) / 3.0) : (7.787 * z + 16/116);

        l = y > 0.008856 ? (116.0 * y3 - 16.0) : 903.3 * y;
        a = (x - y) * 500.0;
        b = (y - z) * 200.0;

        uchar3 fPixel;

        fPixel.x = static_cast<uchar>(l * 255 / 100) ;
        fPixel.y = static_cast<uchar>(a + 128);
        fPixel.z = static_cast<uchar>(b + 128);

        dst(py, px) = fPixel;
    }
}

BGR to Lab conversion

Hi all, I wrote the code for RGB to lab color conversion for cuda by using mathematical formulae which are mentioned in the OpenCV documentation but when I compare the l ,a ,b values from the cvColor function and my cuda function, there is a difference of 5 to 15. It will be great, if you suggest me the way.

__global__ void kRgb2CIELab(PtrStepSz<uchar3> src, PtrStepSz<uchar3> dst, int width, int height) {

    int px = blockIdx.x * blockDim.x + threadIdx.x;
    int py = blockIdx.y * blockDim.y + threadIdx.y;

    if (px < width && py < height)
    {

        uchar3 nPixel = src(py, px);

        float blue = (float)nPixel.x / 255.0;
        float green = (float)nPixel.y / 255.0;
        float red = (float)nPixel.z / 255.0;

        float x = red * 0.412453 + green * 0.357580 + blue * 0.180423;
        float y = red * 0.212671 + green * 0.715160 + blue * 0.072169;
        float z = red * 0.019334 + green * 0.119193 + blue * 0.950227;

        x /= 0.950456;
        float y3 = exp(log(y) / 3.0);
        z /= 1.088754;

        float l, a, b;

        x = x > 0.008856 ? exp(log(x) / 3.0) : (7.787 * x + 16/116);
        y = y > 0.008856 ? y3 : 7.787 * y + 16/116;
        z = z > 0.008856 ? z /= exp(log(z) / 3.0) : (7.787 * z + 16/116);

        l = y > 0.008856 ? (116.0 * y3 - 16.0) : 903.3 * y;
        a = (x - y) * 500.0;
        b = (y - z) * 200.0;

        uchar3 fPixel;

        fPixel.x = static_cast<uchar>(l * 255 / 100) ;
        fPixel.y = static_cast<uchar>(a + 128);
        fPixel.z = static_cast<uchar>(b + 128);

        dst(py, px) = fPixel;
    }
}

BGR to Lab conversionconversion issue

Hi all, I wrote the code for RGB to lab color conversion for cuda by using mathematical formulae which are mentioned in the OpenCV documentation but when I compare the l ,a ,b values from the cvColor function and my cuda function, there is a difference of 5 to 15. It will be great, if you suggest me the way.

__global__ void kRgb2CIELab(PtrStepSz<uchar3> src, PtrStepSz<uchar3> dst, int width, int height) {

    int px = blockIdx.x * blockDim.x + threadIdx.x;
    int py = blockIdx.y * blockDim.y + threadIdx.y;

    if (px < width && py < height)
    {

        uchar3 nPixel = src(py, px);

        float blue = (float)nPixel.x / 255.0;
        float green = (float)nPixel.y / 255.0;
        float red = (float)nPixel.z / 255.0;

        float x = red * 0.412453 + green * 0.357580 + blue * 0.180423;
        float y = red * 0.212671 + green * 0.715160 + blue * 0.072169;
        float z = red * 0.019334 + green * 0.119193 + blue * 0.950227;

        x /= 0.950456;
        float y3 = exp(log(y) / 3.0);
        z /= 1.088754;

        float l, a, b;

        x = x > 0.008856 ? exp(log(x) / 3.0) : (7.787 * x + 16/116);
        y = y > 0.008856 ? y3 : 7.787 * y + 16/116;
        z = z > 0.008856 ? z /= exp(log(z) / 3.0) : (7.787 * z + 16/116);

        l = y > 0.008856 ? (116.0 * y3 - 16.0) : 903.3 * y;
        a = (x - y) * 500.0;
        b = (y - z) * 200.0;

        uchar3 fPixel;

        fPixel.x = static_cast<uchar>(l * 255 / 100) ;
        fPixel.y = static_cast<uchar>(a + 128);
        fPixel.z = static_cast<uchar>(b + 128);

        dst(py, px) = fPixel;
    }
}

BGR to Lab conversion issue

Hi all, I wrote the code for RGB to lab color conversion for cuda by using mathematical formulae which are mentioned in the OpenCV documentation but when I compare the l ,a ,b values from the cvColor function and my cuda function, there is a difference of 5 to 15. It will be great, if you suggest me the way.

__global__ void kRgb2CIELab(PtrStepSz<uchar3> src, PtrStepSz<uchar3> dst, int width, int height) {

 int px = blockIdx.x * blockDim.x + threadIdx.x;
 int py = blockIdx.y * blockDim.y + threadIdx.y;
 

if (px < width && py < height) { {

    uchar3 nPixel pixel = src(py, px);

     float blue = (float)nPixel.x (float)pixel.x / 255.0;
     float green = (float)nPixel.y (float)pixel.y / 255.0;
     float red = (float)nPixel.z (float)pixel.z / 255.0;

     float x = red * 0.412453 + green * 0.357580 + blue * 0.180423;
     float y = red * 0.212671 + green * 0.715160 + blue * 0.072169;
     float z = red * 0.019334 + green * 0.119193 + blue * 0.950227;

     x /= = x / 0.950456;
        float y3 = exp(log(y) / 3.0);
        z /= = z / 1.088754;

     float l, a, b;

        x float fx = x > 0.008856 ? exp(log(x) / 3.0) cbrt(x) : (7.787 * x + 16/116);
        y 16. / 116.);
    float fy = y > 0.008856 ? y3 cbrt(y) : 7.787 * y + 16/116;
        z 16. / 116.;
    float fz = z > 0.008856 ? z /= exp(log(z) / 3.0) cbrt(z) : (7.787 * z + 16/116);

    16. / 116.);

    l = y > 0.008856 ? (116.0 * y3 cbrt(y) - 16.0) : 903.3 * y;
     a = (x (fx - y) fy) * 500.0;
     b = (y (fy - z) fz) * 200.0;

     uchar3 fPixel;

        fPixel.x uPixel;

    uPixel.x = static_cast<uchar>(l * 255 / 100) ;
        fPixel.y 255. / 100.);
    uPixel.y = static_cast<uchar>(a + 128);
        fPixel.z uPixel.z = static_cast<uchar>(b + 128);

     dst(py, px) = fPixel;
    }
uPixel;
}

}

BGR to Lab conversion issue

Hi all, I wrote the code for RGB to lab color conversion for cuda by using mathematical formulae which are mentioned in the OpenCV documentation but when I compare the l ,a ,b values from the cvColor function and my cuda function, there is a difference of 5 to 15. It will be great, if you suggest me the way.way. I have attched screenshot.

Gpu labframe = conversion by using mathematical equations. Cpu labframe = conversion by using cvtcolor function

__global__ void kRgb2CIELab(PtrStepSz<uchar3> src, PtrStepSz<uchar3> dst, int width, int height) {

int px = blockIdx.x * blockDim.x + threadIdx.x;
int py = blockIdx.y * blockDim.y + threadIdx.y;

if (px < width && py < height) {

{

    uchar3 pixel = src(py, px);

    float blue = (float)pixel.x / 255.0;
    float green = (float)pixel.y / 255.0;
    float red = (float)pixel.z / 255.0;

    float x = red * 0.412453 + green * 0.357580 + blue * 0.180423;
    float y = red * 0.212671 + green * 0.715160 + blue * 0.072169;
    float z = red * 0.019334 + green * 0.119193 + blue * 0.950227;

    x = x / 0.950456;
    z = z / 1.088754;

    float l, a, b;

    float fx = x > 0.008856 ? cbrt(x) : (7.787 * x + 16. / 116.);
    float fy = y > 0.008856 ? cbrt(y) : 7.787 * y + 16. / 116.;
    float fz = z > 0.008856 ? cbrt(z) : (7.787 * z + 16. / 116.);

    l = y > 0.008856 ? (116.0 * cbrt(y) - 16.0) : 903.3 * y;
    a = (fx - fy) * 500.0;
    b = (fy - fz) * 200.0;

    uchar3 uPixel;

    uPixel.x = static_cast<uchar>(l * 255. / 100.);
    uPixel.y = static_cast<uchar>(a + 128);
    uPixel.z = static_cast<uchar>(b + 128);

    dst(py, px) = uPixel;
}

}

BGR to Lab conversion issue

Hi all, I wrote the code for RGB to lab color conversion for cuda by using mathematical formulae which are mentioned in the OpenCV documentation but when I compare the l ,a ,b values from the cvColor function and my cuda function, there is a difference of 5 to 15. It will be great, if you suggest me the way. I have attched screenshot.

Gpu labframe = conversion by using mathematical equations. Cpu labframe = conversion by using cvtcolor function

__global__ void kRgb2CIELab(PtrStepSz<uchar3> src, PtrStepSz<uchar3> dst, int width, int height) {

int px = blockIdx.x * blockDim.x + threadIdx.x;
int py = blockIdx.y * blockDim.y + threadIdx.y;

      if (px < width && py < height)
{

    uchar3 pixel = src(py, px);

    float blue = (float)pixel.x / 255.0;
    float green = (float)pixel.y / 255.0;
    float red = (float)pixel.z / 255.0;

    float x = red * 0.412453 + green * 0.357580 + blue * 0.180423;
    float y = red * 0.212671 + green * 0.715160 + blue * 0.072169;
    float z = red * 0.019334 + green * 0.119193 + blue * 0.950227;

    x = x / 0.950456;
    z = z / 1.088754;

    float l, a, b;

    float fx = x > 0.008856 ? cbrt(x) : (7.787 * x + 16. / 116.);
    float fy = y > 0.008856 ? cbrt(y) : 7.787 * y + 16. / 116.;
    float fz = z > 0.008856 ? cbrt(z) : (7.787 * z + 16. / 116.);

    l = y > 0.008856 ? (116.0 * cbrt(y) - 16.0) : 903.3 * y;
    a = (fx - fy) * 500.0;
    b = (fy - fz) * 200.0;

    uchar3 uPixel;

    uPixel.x = static_cast<uchar>(l * 255. / 100.);
    uPixel.y = static_cast<uchar>(a + 128);
    uPixel.z = static_cast<uchar>(b + 128);

    dst(py, px) = uPixel;
}

}

BGR to Lab conversion issue

Hi all, I wrote the code for RGB to lab color conversion for cuda by using mathematical formulae which are mentioned in the OpenCV documentation but when I compare the l ,a ,b values from the cvColor function and my cuda function, there is a difference of 5 to 15. It will be great, if you suggest me the way. I have attched attached screenshot.

Gpu labframe = conversion by using mathematical equations. Cpu labframe = conversion by using cvtcolor function

__global__ void kRgb2CIELab(PtrStepSz<uchar3> src, PtrStepSz<uchar3> dst, int width, int height) {

int px = blockIdx.x * blockDim.x + threadIdx.x;
int py = blockIdx.y * blockDim.y + threadIdx.y;

      if (px < width && py < height)
{

    uchar3 pixel = src(py, px);

    float blue = (float)pixel.x / 255.0;
    float green = (float)pixel.y / 255.0;
    float red = (float)pixel.z / 255.0;

    float x = red * 0.412453 + green * 0.357580 + blue * 0.180423;
    float y = red * 0.212671 + green * 0.715160 + blue * 0.072169;
    float z = red * 0.019334 + green * 0.119193 + blue * 0.950227;

    x = x / 0.950456;
    z = z / 1.088754;

    float l, a, b;

    float fx = x > 0.008856 ? cbrt(x) : (7.787 * x + 16. / 116.);
    float fy = y > 0.008856 ? cbrt(y) : 7.787 * y + 16. / 116.;
    float fz = z > 0.008856 ? cbrt(z) : (7.787 * z + 16. / 116.);

    l = y > 0.008856 ? (116.0 * cbrt(y) - 16.0) : 903.3 * y;
    a = (fx - fy) * 500.0;
    b = (fy - fz) * 200.0;

    uchar3 uPixel;

    uPixel.x = static_cast<uchar>(l * 255. / 100.);
    uPixel.y = static_cast<uchar>(a + 128);
    uPixel.z = static_cast<uchar>(b + 128);

    dst(py, px) = uPixel;
}

}

BGR to Lab conversion issue

Hi all, I wrote the code for RGB to lab color conversion for cuda by using mathematical formulae which are mentioned in the OpenCV documentation but when I compare the l ,a ,b values from the cvColor function and my cuda function, there is a difference of 5 to 15. It will be great, if you suggest me the way. I have attached screenshot.

Gpu labframe = conversion by using mathematical equations. Cpu labframe = conversion by using cvtcolor function

__global__ void kRgb2CIELab(PtrStepSz<uchar3> src, PtrStepSz<uchar3> dst, int width, int height) {

int px = blockIdx.x * blockDim.x + threadIdx.x;
int py = blockIdx.y * blockDim.y + threadIdx.y;

      if (px < width && py < height)
{

    uchar3 pixel = src(py, px);

    float blue = (float)pixel.x / 255.0;
    float green = (float)pixel.y / 255.0;
    float red = (float)pixel.z / 255.0;

    float x = red * 0.412453 + green * 0.357580 + blue * 0.180423;
    float y = red * 0.212671 + green * 0.715160 + blue * 0.072169;
    float z = red * 0.019334 + green * 0.119193 + blue * 0.950227;

    x = x / 0.950456;
    z = z / 1.088754;

    float l, a, b;

    float fx = x > 0.008856 ? cbrt(x) : (7.787 * x + 16. / 116.);
    float fy = y > 0.008856 ? cbrt(y) : 7.787 * y + 16. / 116.;
    float fz = z > 0.008856 ? cbrt(z) : (7.787 * z + 16. / 116.);

    l = y > 0.008856 ? (116.0 * cbrt(y) - 16.0) : 903.3 * y;
    a = (fx - fy) * 500.0;
    b = (fy - fz) * 200.0;

    uchar3 uPixel;

    uPixel.x = static_cast<uchar>(l * 255. / 100.);
    uPixel.y = static_cast<uchar>(a + 128);
    uPixel.z = static_cast<uchar>(b + 128);

    dst(py, px) = uPixel;
}

}