02-24-2009 01:43 AM
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~~~~
Solved! Go to Solution.
02-24-2009 03:08 AM
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.
02-26-2009 02:43 AM
02-26-2009 04:01 AM
03-04-2009 01:26 AM
03-04-2009 02:11 PM
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...
03-04-2009 11:07 PM