Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Directly accessing image as an array

GetImagePixelPtr returns a pointer to the image, and is useful for passing to an external routine.  Is there a way to use this function (or a similar one) to address the image from LabVIEW directly - as a normal LabVIEW array?  At the moment, I use ImageToArray, but this is not feasible for large images as it allocates a new block of memory for the array.
0 Kudos
Message 1 of 4
(3,583 Views)

GregS -

 

You can use GetImagePixelPtr with IMAQ MemPeek to get the raw bytes out of the image.  I've attached a sample of reading the first 5 pixels out of a U8 image.

 

Do you mind if I ask what you're planning on doing with the raw memory?  Obviously it's a lot easier to use the builtin Vision functions to manipulate and analyze images, and I'm curious if you're planning on implementing an algorithm we don't support.

 

Greg Stoll

Vision R&D

National Instruments

Greg Stoll
LabVIEW R&D
0 Kudos
Message 2 of 4
(3,569 Views)

As far as I can understand, you not happy with array allocation logic.

Well, what you can do is following - allocate LabVIEW array before, then call your DLL, which will receive pointer to just created array, and pointer obtained from GetImagePixelPtr, then copy image to your array.

But if your application is time critical, I will recommend to stay away from LabVIEW arrays, and do all what you needed with native Vision functions, or with your own DLLs. Working with LabVIEW arrays is not the fastest way.

 

Andrey.

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

Thanks for the MemPeek function, but this seems to allocate memory for the string, not directly address the image data, so I'm not sure I'm any better off.

 

I have a number of algorithms that I can't use Vision functions for, the most significant probably being wavelet processing, for which I'm using the Wavelet Analysis addon.  I use wavelets both for denoising, and for downsampling images.  I also have a Region Growing (i.e. Magic Wand) routine that is much faster using arrays than using Vision routines, although it can be done either way - in general it seems that functions that need to work pixel-by-pixel are much slower using images than using arrays.

 

I have a number of other functions that I also perform on arrays (e.g. deconvolution) which could equally be written to use images - the reason I don't is that I need the same functionality for 3D image data, so it's a slightly different reason (maybe I should ask if Vision will ever support 3D images!).

 

I guess my question is a little more general, in that it seems restrictive not to be able to use any of the (excellent) signal processing and analysis routines in LabVIEW directly on images.  I guess I'm thinking about something like the ArrayToMatrix VI, which essentially repackages an array as a Matrix - I just want an image to look like an array so that it can be passed to these sort of analysis routines - perhaps the In-Place Memory structure could be extended to handle something like this.

 

Cheers ~ Greg

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