Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Local standard deviation or variance of an image

This is not so much a question as a solution. I had a difficult time finding a means of doing a local (3x3 or 5x5) standard deviation for each pixel in an image for using in a real-time speckle image analysis instrument. So I wanted to post a solution that I have come up with in case anyone else had run into the same problem. The fastest method I found (versus breaking the image down into numerous YxY arrays) is to use several IMAQ image math functions in tandem. Here is the posted solution. Please post any questions/comments. If there is any faster/simpler way to do this, please let me know. This step is the rate limiting time step in my imaging processing, and any suggestions for improvements would be greatly appreciated.

Download All
Message 1 of 5
(4,068 Views)

Nice!  I had also coded exactly the same algorithm -- I'm pretty sure it is as fast as you can get.  The only frustration is requiring conversion to an array in order to compute the square root.  One solution would be to ask for an IMAQ Sqrt function, although my preference is to provide direct access to the image data using an In Place Element Structure.  See this Idea Exchange entry for a description of what I mean, which in my opinion is greatly under-appreciated! Smiley Happy

 

 

0 Kudos
Message 2 of 5
(4,066 Views)

Thanks for posting!

Marti C
Applications Engineer
National Instruments
NI Medical
0 Kudos
Message 3 of 5
(4,050 Views)

My only thought is to use a lookup table instead of the square root function.  You could very quickly generate a lookup table that gives the square root of the original value, and it would only need to be generated once.  A lookup table will be much faster than calculating the square root of each pixel, and it won't require image to array or array to image.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 4 of 5
(4,040 Views)

Whoops.  I thought you were using integer images.  Floating point images can't be converted using a lookup table unless you don't mind losing a lot of resolution.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 5 of 5
(4,038 Views)