LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

"Convert image to array" uses imaq function

Hi,
    When I use the imaq function "imaqimagetoarray", I was supposed to have a 2-D array for the pixel values of the image. However, all I can do is use a pointer point to the image data, and use "for loop" to put  the data into the 2-D array. The manual says that this function will create a 2-D array. How can I directly put the image pixel into the 2-D array without using "for loop"??  Thank you very much!!
 
Mitchell
0 Kudos
Message 1 of 7
(5,669 Views)
Hi Mitchel,

The void* that is returned is actually a 2-D array implemented as pointers instead of a staticly declared 2-D array of fixed size.  This way you can change both the type and the size of your image dynamically without having to call a different function.  You can address the indices in the pointer array the same way you address indices in a static array.  If you want to put the values returned from the imaqImageToArray function into a statically sized array such as one declared like: int array[100][100]; then you will need to use a for loop to load the values from the pointer array to the static one.  Hope this helps to answer your question.


S. Arves S.
National Instruments
Applications Engineer
0 Kudos
Message 2 of 7
(5,651 Views)

   Hi,

I'm looking to compare two images, looking for a result of 0-100% on how they match, originally I was coverting my image to an array,  with the code below, but this is taking far to long. From what your saying, we can use the 2-D array returned as pointers, but how can I compare this way. I originally intended to Subtract one from the other and get the difference.

Any ideas 🙂

 

    myImage= imaqSnap (Sid,myImage , IMAQ_NO_RECT);
    imaqDisplayImage (myImage, 0, TRUE);
    
    myImage1= imaqSnap (Sid,myImage1 , IMAQ_NO_RECT);
    imaqDisplayImage (myImage1, 0, TRUE);

    
    convertedData = imaqImageToArray (myImage, IMAQ_NO_RECT, &columns, &rows); 
    convertedData1 = imaqImageToArray (myImage1, IMAQ_NO_RECT, &columns, &rows); 

    
    *convertedData1

 

      // for (j=0; j<rows; j++)
      // {
       //  for (i=0; i<columns; i++)
      //  {
      //   //fills a 2-D array with original pixel values plus a user-defined constant offset
      //   data[j][i] = *convertedData + val;
      //   convertedData++;  //moves to the next original pixel in the array
      //  }
      // }
    

0 Kudos
Message 3 of 7
(5,372 Views)
what do you mean by "this is taking far to long" ? how much time does it take to perform the transformation ? also, have you tried without the imaqDisplayImage (which is useless for comparison) ?

please be aware that NIVision is far from being the fastest image processing library, some operations are slooooow. if converting the image to a 2D array is too slow, you might use the pointer to the first pixel (see
imaqGetImageInfo, field imageStart), then go through the entire image: pixels are stored contiguously left-to-right top-to-bottom order in the image data. you have to be careful with the size of the image but this is the fastest way i can think of performing manual operations on an image.

by the way: you can read data this way, but also write pixels using the same instructions.
0 Kudos
Message 4 of 7
(5,351 Views)
Hello,

Consider using imaqSubtract to compare pixel values for you.  You could then analyze the destination image to understand how similar the two source images are.  Also, if you are looking to compare one image to many images, consider using the GoldenTemplateInspection.prj shipping example.

Best Regards,
T. McCarty
0 Kudos
Message 5 of 7
(5,339 Views)

Are these functions available only with a licensed version of NI Vision? which I don't have, is there an alternative, other than spending 2999eruo on a Vision license?

Thanks

pb

0 Kudos
Message 6 of 7
(5,324 Views)
You are always free to write your own algorithms, but using the Vision Development Module may save you time.  You can download an evaluation version here.

Best Regards,
T. McCarty 
0 Kudos
Message 7 of 7
(5,287 Views)