Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:41:28+00:00 2026-06-09T02:41:28+00:00

I am using opencv for a certain image processing code. I need to extract

  • 0

I am using opencv for a certain image processing code. I need to extract the color layers from a certain picture. So what I do is keep the pixels having a certain value and set the remaining pixels to the background color (which is white in this case). For certain issues I have to carry out this entire operation in CIE-L*a*b* color space. The problem arises when I convert the above image to RGB, using cvCvtColor() the background no longer remains white. I have tried with different permutation and combination of values, but it either becomes red or blue or anything but not pure white.

I even made a picture in paint (just white) and converted it to L*a*b* space and printed the values in a text file. Here is the code

IplImage *image, *lab;
uchar *data;
FILE *fp;
int i, j;
image = cvLoadImage( "white.png", CV_LOAD_IMAGE_UNCHANGED);
lab = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, 3);
cvCvtColor(image, lab, CV_BGR2Lab);
data = (uchar*)lab->imageData;
fp= fopen("white.txt", "w");
for(i=0; i<lab->height; i++)
         for(j=0; j<lab->width; j++)
                  fprintf(fp, "L = %d, a = %d, b = %d\n", data[i*lab->widthStep + j*lab->nChannels +0], data[i*lab->widthStep + j*lab->nChannels +0], data[i*lab->widthStep + j*lab->nChannels +0]);

It shows all the three values to be 255. But when I set the pixel values in my required program to it, it becomes reddish.

Here is the code snippet to set the pixel value

image = cvLoadImage( "pic11.png", CV_LOAD_IMAGE_UNCHANGED);
cvCvtColor(image, lab, CV_BGR2Lab);

copy = cvCreateImage(cvSize(lab->width,lab->height), IPL_DEPTH_8U, 3);
cvCopy(lab, copy, NULL);
data2 = (uchar*)copy->imageData;    

copied = cvCreateImage(cvSize(copy->width,copy->height), IPL_DEPTH_8U, 3);
data = (uchar*)copied->imageData;

for(i=x; i<copy->height; i++)
          for(j=y; j<copy->width; j++)
          {        
                   if(data2[i*copy->widthStep + j*copy->nChannels + 0] == r &&
                      data2[i*copy->widthStep + j*copy->nChannels + 1] == g &&
                      data2[i*copy->widthStep + j*copy->nChannels + 2] == b)
                   {
                           data[i*copy->widthStep + j*copy->nChannels + 0] = r;
                           data[i*copy->widthStep + j*copy->nChannels + 1] = g;
                           data[i*copy->widthStep + j*copy->nChannels + 2] = b;
                   }
                   else
                   {
                       data[i*copy->widthStep + j*copy->nChannels + 0] = 255;
                       data[i*copy->widthStep + j*copy->nChannels + 1] = 255;
                       data[i*copy->widthStep + j*copy->nChannels + 2] = 255;
                   }
          }

copy_im = cvCreateImage(cvSize(copied->width,copied->height), IPL_DEPTH_8U, 3);
cvCvtColor(copied, copy_im, CV_Lab2BGR);
cvSaveImage("copy.jpg", copy_im);

Any help would be highly appreciated. Thanks in advance !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:41:30+00:00Added an answer on June 9, 2026 at 2:41 am

    To sum up the comments roughly:

    In L*a*b* The values are normally [0,100] and “a and “b” are signed, with no well defined boundaries. In opencv for 8 bit images the values are converted as follows:

    • L <- L * 255/100
    • a <- a+128
    • b <- b+128

    In CIELab, “white” is represented roughly as (100,0,0) which becomes (255,128,128) by that transformation. If you use 32-bit floating point images, then this last conversion is not needed and you can use (100.0,0.0,0.0) as white.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using OpenCV for some of my image processing related codes. I am
I am using OpenCV 2.3.1 in Android. I need to crop the image into
Do you recommend using OpenCV for doing image processing using C++ ? Thanks.
I am using OpenCV static library in Objective-C to do some image processing, and
I'm using opencv and I need to obtain a single region of white pixels
I'm using OpenCV to filter an image for certain colours, so I've got a
I'm using OpenCV v2.4.1 And this is the code I'm using #include opencv2/opencv.hpp #include
I'm using OpenCV 2.3.2 library downloaded from OpenCV trunk. I want to use setOpenGlDrawCallback
I'm using OpenCV to fit a line from a set of points using cvFitLine()
I'm trying to display an image using OpenCV. I have the following very basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.