Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

BGR to Lab conversion issue

$
0
0
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 src, PtrStepSz 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(l * 255 / 100) ; fPixel.y = static_cast(a + 128); fPixel.z = static_cast(b + 128); dst(py, px) = fPixel; } }

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>