Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

running average of images

Anyone know how to do a running average of images? I could convert images to 2-D arrays and stack in a 3-D array. I can't think of a way to add the images once in the 3-D array without a loop that would slow execution speed to a crawl.
0 Kudos
Message 1 of 8
(5,783 Views)
This example demonstrates how to use a running average to remove transients from captured images.

1. Set up an acquisition and create a storage buffer, a working buffer for the current image, and a repository for the running average. The running average is a 16-bit buffer to allow for up to 256 8-bit images to be averaged together.
2. Create an array of buffers to hold each of the images being averaged. This array works as a shift register to subtact the oldest image (step 4) and add the newest image (step 6)
3. The calculation determines which index of the array to access. This index is then indexed for use in this iteration of the loop.
4. For each iteration, first subtract the oldest image from the repository. You cannot subtract images that have not been stored, so subtracting occurs on the second iteration of the loop.
5. The newly acquired image is converted to a 16-bit image and stored in the current index of the array.
6. Add the current index to the repository and display the image. 16-bit images are dynamically ranged when displayed so that the image displayed is the average of all images added to the repository. Steps 4, 5, and 6 repeat, subtracting the oldest image and adding the newest image to create a running average.
7. 16-bit images are signed. This step subtracts 2^15 from the repository the first time through the loop and allows access to the entire 16-bits of resolution.
8. This step scales the histograms so that the histogram for 16-bit (average) and 8-bit (current) images cover the same range.
9. Dispose of the buffers and WindDraw windows.
10. This loop calculates the frames per second being handled. Notice the use of notifiers to end this while loop when the main loop ends.

NOTE: You must have IMAQ Vision installed to run this example. The maximum number of buffers used should be no greater than 255 for 8 bit images.
Message 2 of 8
(5,773 Views)
Great solution. I am new to the low level VIs but was able to follow your logic after some reading. Could this VI be modified to work with 16 bit images? I won't be adding more than 20 16 bit images with unsigned data in my running average.
Thanks
0 Kudos
Message 3 of 8
(5,764 Views)
Hi Air Force 1,

The only problem with going to 16 bit on this example is that the IMAQ Histograph only accepts 8 bit images, as do many other vision functions. You can always check this out by opening the context help for each function (hover your mouse over the subVI and press CTRL+H). If you take a look at the IMAQ Histograph help it says that it only accepts 8 bit images.

Regards

Dan
National Instruments
0 Kudos
Message 4 of 8
(5,738 Views)
I would like to use this Running Averages VI, but my camera uses the IMAQ1394 VIs.  Is there a way to create the buffers for IMAQ1394 like there is for IMAQ?
0 Kudos
Message 5 of 8
(5,303 Views)
Hello Morris,

It is possible to configure buffers with the IMAQ 1394 VIs.  You can use the "IMAQ 1394 Configure Acquisition" and set the number of Buffers.  You can then use the "IMAQ Get Image" or "IMAQ Get Image Data" VIs to extract the images out of kernel level memory and into user space memory which is then used in LabVIEW.  It is a little different configuring buffers with the regular IMAQ VIs.  There is a good example of how buffers are configured that is shipped with the IMAQ 1394 driver called "Low-Level Sequence.vi".  I hope this information helps.  Thanks and have a great day.

Regards,
Mark T
Applications Engineer
National Instruments
0 Kudos
Message 6 of 8
(5,286 Views)

@T-Route wrote:
Hello Morris,

It is possible to configure buffers with the IMAQ 1394 VIs.  You can use the "IMAQ 1394 Configure Acquisition" and set the number of Buffers.  You can then use the "IMAQ Get Image" or "IMAQ Get Image Data" VIs to extract the images out of kernel level memory and into user space memory which is then used in LabVIEW.  It is a little different configuring buffers with the regular IMAQ VIs.  There is a good example of how buffers are configured that is shipped with the IMAQ 1394 driver called "Low-Level Sequence.vi".  I hope this information helps.  Thanks and have a great day.

Regards,
Mark T
Applications Engineer
National Instruments
 

Hi All,

 

I am new to Imge processing with Labview, I have same case of creating the running average of images using Gige vision camera I couldnt figure out as how to change this program for the gige vision , I dnt need to get histogram or any thing just a simple ruuning average or median of images in real time.

0 Kudos
Message 7 of 8
(4,373 Views)
Hi AnkitG,

-I'm assuming, if you want to change it to GigE you might need to use IMAQdx functions to acquire and configure acquisition instead of IMAQ functions.
-Rest of the image processing functions might be applicable same.
Thanks
uday
0 Kudos
Message 8 of 8
(4,356 Views)