LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use GetImagePixelPtr?

Hi,

I am fighting hard with passing an image to an external DLL.

For this I am using the IMAQ GetImagePixelPtr VI which returns an unsigned long*

1. I am not sure where this pointer points to as there is different information availabe. In one place it says the border is part of the contigous data and therefore the pointer will point to the first border pixel. In another place it says that it will point to the Pixel(0,0) by default. What is true?

2. I pass the pointer to my function test(unsigned long* LVImagePtr) and then I print LVImagePtr[0]
This prints the address of LVImagePtr. Is this stored in the image data? That would be strange as it would corrupt my image data. So I guess it is in the alignment area, but this is not documented anywhere.

3. How can I access the data properly? I am using a completely white 8 bit image, so all values should be 255. And I thought this would be stored as a char array.
So I tried casting the unsigned long* to an unsigned char*
unsigned char* image = (unsigned char*)LVImagePtr;
But I got always different values for random chosen pixels via image[xy]
trying to use LVImagePtr[xy] also gave me strange results.

Thanks for reading and have a nice day,

Bernie
0 Kudos
Message 1 of 5
(2,759 Views)
Ok, I figured out why it wasn't working.

That LVImagePtr[0] gives the address of the data is ok, because in my case LVImagePtr is not an Pointer as I thought, it is an Pointer to a value.

So if I write

unsigned char* image = (unsigned char*)*LVImagePtr;

everything is fine.
0 Kudos
Message 2 of 5
(2,754 Views)
I think the simplest solutions is
1. When you make code interface node, configure the parameters as follows
Type: Numeric
Data type: 32-bit unsigned integer
Pass: “Value” not “Pointer to value”

2. When you create C code, the prototype would be like this. In this example, I use an input image, an output image and dimensions as parameters.

/* Call Library source file */
#include "extcode.h"
long threshold2(unsigned long inputPtr, unsigned long outputPtr, unsigned short xsize, unsigned short ysize);
long threshold2(unsigned long inputPtr, unsigned long outputPtr, unsigned short xsize, unsigned short ysize)
{
/* Insert code here */
}

Do not believe it! If you use 8-bit unsigned integer, rewrite “unsigned long inputPtr” to “unsigned char* inputPtr". As the same manner, if you want to manipulate 32-bit unsigned integer for multi-color image, rewrite to “unsigned long* inputPtr”.

3.Write any code in /* Insert code here */ section. I recommend you to write this simple code first. This code makes all the pixels to white. Be careful that a LabVIEW image has border pixels. You have to skip as needed.
int i;
for(i=0; i inputPtr[i]=255; /* *(inputPtr+i)=255; will work*/
}

I hope this information will help you.

Yutaka
0 Kudos
Message 3 of 5
(2,728 Views)
I am sorry, the code is as follows

int i;
for(i=0; iinputPtr[i]=255; /* or *(inputPtr+i)=255;)*/
}
0 Kudos
Message 4 of 5
(2,742 Views)
I am sorry, this BBS system has some problem.
I can't write the character expresses "smaller than".

In the code above, I want to specify the range of "i" from 0 to xsize*ysize.
0 Kudos
Message 5 of 5
(2,716 Views)