LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

16bit to 8bit image conversion

Hi,
 
I am using Labview 7.1 and IMAQ Vision (June 2003 Edition) under Windows XP SP2 and I am searching for the fastest way to
convert 16bit grayscale images to 8bit grayscale images. I would like to use the same routine
that IMAQ uses internally to display 16bit Images on the control panel and that can be controlled by the
16-bit Display Mapping Property Node for image controls, but I cannot find the matching IMAQ command.
The only command I found is the IMAQ Cast Image command which doesn't give me the same options as the image property node.
 
I have programmed the same conversion on my own in Labview+IMAQ, but the my routine seems to  be much slower
than the internally use one from IMAQ.
 
Does anybody know who to access IMAQs 16-bit Display Mapping routine to convert 16bit grayscale images to 8bit grayscale images
or has written a routine which is similar powerful?
 
Thanks
 
Ronnn
 
0 Kudos
Message 1 of 6
(7,858 Views)

Convert a 16 bit gray scale image to 8 bit is easy.  No IMAQ needed.

Simply divide the U16 array by 0xFFFF, and multiple by 0xFF, then convert double to U8.

The color table is (array of U32): 0x010101, 0x020202, ..., 0xFFFFFF.

You are loosing a lot gray scales, from 65335 to 256.  Lots of gray level merged into the same level.  Therefore, you might want to do a contrast strentch before convert:

Use array max/min to get the max and min of the array.  Substract the min from the array, and then divid the array by (max - min), multiple the array by 0xFFFF.  That will make your lowest gray level to black, and hightest level to white.

Depend on the gray level you use, you might need to do a histogram equlization to avoid all levels merged into the same level.

 

George Zou

http://gtoolbox.yeah.net

George Zou
0 Kudos
Message 2 of 6
(7,842 Views)
Hallo, Ronnn,

probably your conersion routine slow because you have converted IMAQ image to array, then do all with array and then convert back to IMAQ image. You can do it with native IMAQ functions:


Code above executed within 30...40 ms for 512x512 16 bit image on my P4 1,6 GHz.

Source in attachment.

Andrey.
Download All
0 Kudos
Message 3 of 6
(7,839 Views)
Hi George and Andrey,

thanks for your fast and helpful answers!

I indeed originally used the basic Labiew array functions (as also recommend by George)
to do the conversion.

I have programmed another routine which compares the speed of this routine
with another routine using IMAQ functions (as recommended by Andrey, just a bit modified).
(See attachment)

On my Pentium M, 1.7Ghz Laptop a 512x512 16 image gives me:
~14ms for the routine based on array fcts
~16ms for the routine based on IMAQ fcts
The IMAQ routine is probably slightly slower as it has to use the histogram routine.
(Note that the priority of the routine is changed to "time critical priority" for better time measurement.)

The routine also trys to measure the time for displaying the images.
As I measure always 0ms, I believe the task is handled over to the control panel.

I still believe that it should be possible to do this conversion faster.

Are there any undocumented IMAQ fcts that I could use? (Are there any undocumented?)

Thanks again

Ronnn


0 Kudos
Message 4 of 6
(7,809 Views)
Hi again,

Yes, its possible to do this faster.
You can write your own DLL for conversion for reducing overhead, something like this:



This code running twice faster in comparizon with IMAQ or "array" implementation. On my P4 1,6 GHz take 10-12 ms vs 20-22 ms.
Its a "quick and dirty" implementation without any checks, etc, but you can use this as starting point. Complete source code in attachment. You can try improve performance (for example, move 255 / (max - min) outside of for loops, etc).

Another way - if you can use fixed min and max values, and don't need to calculate they dynamically every call, then you can precalculate lookup table only once, and then get your result more faster.

Andrey.
0 Kudos
Message 5 of 6
(7,803 Views)
Hi Andrey,

thanks for your help! This was the answer I needed.
I just need my C++-Compilier get running again ...  haven't used it for a while 🙂

Thanks again
Ronnn
0 Kudos
Message 6 of 6
(7,789 Views)