Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

false coloring of grayscale image

Hello,

I have a grayscale image to which I want to apply false coloring.

Below is a chunk of my code where I loop through all rows and cols of my matrix (matProcessed). For each pixel value, I lookup the desired RGB values from the user's pre-defined lookup table, and then overwrite the pixel in matProcessed accordingly. This all works just fine, except that all underlying intensity information in the original grayscale image is lost when a range of intensity values is simply replaced with a color. I think what I need is more like what the hue/saturation/colorize function in Photoshop would do, where I can colorize a range of grayscale pixels while retaining the underlying variation in intensity of the grayscale values. So how do I do that?

   // I first convert to BGR to colorize: 
    cvtColor(matProcessed, matProcessed, CV_GRAY2BGR);

    int iPxVal=0;
    int index;
    int R=0;
    int G=0;
    int B =0;
    for(int i=0; i<matProcessed.rows; i++){
        for(int j=0; j<matProcessed.cols; j++){
            index = matProcessed.channels()*(matProcessed.cols*i + j);

            // grab the grayscale pixel value:
            iPxVal = matProcessed.data[index + 0];

            // lookup user defined RGB value:
            GetColorFromLUT(iPxVal, &R, &G, &B);

            // R, G and B now hold my RGB values the user desires. 

            matProcessed.data[index + 0] = color.blue();
            matProcessed.data[index + 1] = color.green();
            matProcessed.data[index + 2] = color.red();

        }
    }

Thanks!

false coloring of grayscale image

Hello,

I have a grayscale image to which I want to apply false coloring.

Below is a chunk of my code where I loop through all rows and cols of my matrix (matProcessed). For each pixel value, I lookup the desired RGB values from the user's pre-defined lookup table, and then overwrite the pixel in matProcessed accordingly. This all works just fine, except that all underlying intensity information in the original grayscale image is lost when a range of intensity values is simply replaced with a color. I think what I need is more like what the hue/saturation/colorize function in Photoshop would do, where I can colorize a range of grayscale pixels while retaining the underlying variation in intensity of the grayscale values. So how do I do that?

   // I first convert to BGR to colorize: 
    cvtColor(matProcessed, matProcessed, CV_GRAY2BGR);

    int iPxVal=0;
    int index;
    int R=0;
    int G=0;
    int B =0;
    for(int i=0; i<matProcessed.rows; i++){
        for(int j=0; j<matProcessed.cols; j++){
            index = matProcessed.channels()*(matProcessed.cols*i + j);

            // grab the grayscale pixel value:
            iPxVal = matProcessed.data[index + 0];

            // lookup user defined RGB value:
            GetColorFromLUT(iPxVal, &R, &G, &B);

            // R, G and B now hold my RGB values the user desires. 

            matProcessed.data[index + 0] = color.blue();
            matProcessed.data[index + 1] = color.green();
            matProcessed.data[index + 2] = color.red();

        }
    }

Thanks!