LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make false color on gray scale image? Is there any example of the function imaqSetWindowPalette?

Solved!
Go to solution

Hi~ I'm using LabWindows/CVI & NI vision. I want to apply false color on my gray scale image, yet I don't know how to use the function imaqSetWindowPalette(). Is there any example? or any better idea? Thanks a lot~~~~

0 Kudos
Message 1 of 7
(6,112 Views)
Solution
Accepted by topic author yuemuping

it depends on what you are trying to achieve:

 

1. imaqSetWindowPalette() changes the palette of the display window only. this affects the display, but the underlying image is still in grayscale. 

a simple use is:

{

    const int window = 1;

    Image *image;

    

    /*grab and store your image */

    ...

 

    /* change the palette */

    imaqSetWindowPalette( window, IMAQ_PALETTE_BINARY, NULL, 0 );

    /* display the image */

    imaqDisplayImage( image, window, TRUE );

}

 

as specified in the documentation, the third and fourth parameter of imaqSetWindowPalette() are only used when the palette type is set to IMAQ_PALETTE_USER, in which case you specify the colors you want to use for the display.

{

    /* declare and fill you palette */

    RGBValue palette[256];

    

    /* fill your palette here */

    palette[0].R = 0;

    palette[0].G = 0;

    palette[0].B = 0; 

    palette[0].alpha = 0; 

    palette[1].R = 255; 

    palette[1].G = 0; 

    palette[1].B = 0; 

    palette[1].alpha = 0; 

    /* etc. */

   

    /* use the palette */

    imaqSetWindowPalette( window, IMAQ_PALETTE_USER, palette, sizeof( palette ) / sizeof( *palette ) );

}

 

for fixed palette, you can also set you palette with an initializer:

RGBValue palette[256] = {{0,0,0,0},{255,0,0,0},{0,255,0,0}}; /* you have to write the 256 color values you want your palette to be composed of */

 

2. if you want the palette to be definitive when saving the image with the new palette applied, you can specify the palette in the call to imaqWriteFile().

 

3. or you may convert your image to RGB (imaqCast()) then... you are on your own: for an unknown reason, the lookup table in a call to imaqCast() when converting from 8bit grayscale to RGB is not documented as being used. error in the documentation ? deliberate feature removal ? you can eventually test what happens if you specify one.

Message 2 of 7
(6,104 Views)
Thank you very much, dummy_decoy! Well, another question, Can I use the ColorChangePopup() to  choose colors? Since I like the interactive execution window very much. I've tested to use ColorChangePopup() and SetCtrlAttribute(), in the hope of changing my image's color. However, the control ID problem came again.......
0 Kudos
Message 3 of 7
(6,081 Views)
image from the NI Vision library have nothing to do with the User Interface Library, so using SetCtrlAttribute() will never have any effect on an image. however, you can use ColorChangePopup() and register a callback function. the callback should store the new color into the palette, and call imaqSetWindowPalette() to update the display, passing the new modified palette as an argument. (refer to the second example of my previous post to see how to declare a palette and how to use it in a call to imaqSetWindowPalette() ).
0 Kudos
Message 4 of 7
(6,072 Views)
Dummy-decoy, Thank you very  much! When I used the Rainbow type, the image looks pretty beautiful, However, when I uesd the palette User Specified as red( palette[1].R = 255;   palette[1].G = 0;   palette[1].B = 0; ), the image looks terrible. Is there anything wrong? Plz have a look at the attachment. And an additional question: does imaqMergeOverlay() have the same application as imaqSetWindowPalette? Thanks a lot! 
Download All
0 Kudos
Message 5 of 7
(6,018 Views)

well, you should have noticed that palette is an array of 256 elements. there was also a comment which said "/* etc. */", which implied that you should initialize the whole array. the way you do the initialization is up to you: a "for" loop with a mathematical formula for each element depending on the index, or totally random colors, or whatever...

 

ok, here is an example:

 

unsigned int index;

for ( index = 0; index < sizeof( palette ) / sizeof( *pallette ); index++ )

{

    palette[index].R = index;

    palette[index].G = index;

    palette[index].B = index;

    palette[index].alpha = 0;

}

 

this palette will make your picture look like the original one: grayscale.

 

here is another example: double threshold for display.

unsigned int low = 57;

unsigned int high = 142;

 

unsigned int max =  sizeof( palette ) / sizeof( *pallette );

unsigned int index;

for ( index = 0; index < max; index++ )

{

    if ( (index < low) || (index >high) )

    {

        palette[index].R = index;

        palette[index].G = index;

        palette[index].B = index;

        palette[index].alpha = 0;

    }

    else

    {

        palette[index].R = max;

        palette[index].G = 0;

        palette[index].B = 0;

        palette[index].alpha = 0;

    }

}

 

be creative, try any palette you want and have fun with the result...

 

Message 6 of 7
(5,980 Views)
Thanks for ur patient guidance & examples. Now I know a little about it, and have already got what I want. It's really amazing. Thanks a lot! Best Regards! 
0 Kudos
Message 7 of 7
(5,964 Views)