LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting unsigned char from imagetoarray into double

Hi,
 
I'm developing an image processing application in VC++ 2005. I'm using NIVision to load an image and convert it into an array using imagetoarray function.
the image I'm reading is an 8 bit image, which according to the manual returns an array of type unsigned char. I'm also using the fftw library to calculate the fourier transform of the 2D arrays quickly. The fftw function requires the array to be type double. How can I convert it from unsigned char to double without using loops.
 
I can do this with the following code, but it takes too long and time is the important factor.

for (j=0; j<rows; j++)

{

for (i=0; i<column; i++)

{

input[i+column*j] = image[i+column*j];

}

}

Where image is the array returned by the imagetoarray function

Thanks for your help

Harry

0 Kudos
Message 1 of 4
(3,962 Views)
Hi Harry.

You could try the CVI Programmer's Toolbox function ConvertArrayType().

Colin.
0 Kudos
Message 2 of 4
(3,956 Views)

Thanks for your reply,

I'm using just Visual C++ 2005 with NIVision libraries, I'm not using CVI. Does the function ConvertArrayType() come with Labview or IMAQ. Is there any function in NIVision or C++ to convert the type.

thanks

0 Kudos
Message 3 of 4
(3,919 Views)

There's no sensible way of doing this without a loop somewhere or other. Even the library functions have loops in them.

As you're using VC++, you could implement the conversion in assembly language, which would be fastest. Failing that, you could at least get rid of the nested loop:

int nelements=rows*columns;

for (i=0;i<nelements;i++) input[i] = (double)image[i];

Note that VC++, in common with many compilers, will compile much more efficient code to do this conversion in 'release' configurations (with heavy optimisation) rather than in 'debug' configurations. So you might want to consider putting code like this in a separate module or library that is compiled in release mode, and then incorporating that library - rather than the source - into your project. This will enable you to get the performance you want even when debugging the remainder of the code.

--
Martin
Certified CVI Developer
0 Kudos
Message 4 of 4
(3,907 Views)