Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Check Focus Of An Image With Standard LABVIEW Functions

Solved!
Go to solution

Hi,

I would like to determine the best focus quality of a series of color images using standard LABVIEW functions, an example my images would be a 1mm x 2mm ROI of a copper coin or similar sample. I do not have the IMAQ vision toolkit so that will not be an option. Could somebody give me an example of this or point me in the direction I need to go. Is it better to check focus quality on the color image or a black and white image, or perhaps an intensity representation of the image? I have heard that checking the Standard Deviation of a line of pixels within the image would give a good indication of the focus quality by looking for the highest SD value of all the images?

 

Any help is greatly appreciated!

0 Kudos
Message 1 of 14
(9,379 Views)

Hi Jimmy01,

 

I found this example which shows a couple ways to determine the best focus for your system: http://www.ni.com/example/28506/en/

I also found this example, although it uses the IMAQdx drivers.  So you'll have to modify it a bit to work with the IMAQ drivers, but it's doable: https://decibel.ni.com/content/docs/DOC-11090

 

It looks like these examples detect the best focus by measuring the sharpness of the edges.  A stronger edge means the camera is more in focus.  This is also what I was thinking before I found these.  I haven't been able to find anything about using the standard deviation of line pixels, as you mentioned.

Julian R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 14
(9,332 Views)

Thanks for your reply Julian, but as i say i do not and will not have the IMAQ toolkit, i only have the standard labview functions. Is there any examples out there that do not use the IMAQ toolkit? Or perhaps an explanation of what i would need to implement?

 

Thanks.

0 Kudos
Message 3 of 14
(9,323 Views)

Hi Jimmy01,

 

The IMAQ drivers are free, you can download them here: http://www.ni.com/download/ni-vision-acquisition-software-2014.02/4584/en/

 

They come as part of the Vision Acquisition Software, but don't need to be activated like the IMAQdx drivers do (IMAQdx drivers are the ones that require a paid license).  Is it feasible for you to download these and install them, since you don't have to pay for them?

Julian R.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 14
(9,323 Views)

Sorry I didnt explain my situation fully, we do not have the NI Vision Toolkit at all, we only have the base labview package. Does the NI Vision Toolkit require a paid licence? If so how much does it cost and do we need to pay any extra distribution fees when we supply our customers with executables of our application contating this functionality? 

0 Kudos
Message 5 of 14
(9,323 Views)

To measure the focus, extract the line and find the edges.  The simplest method is use differencing - convert array to double, rotate the array by one value, then subtract from the original array.  Take the absolute value, and delete the first point.  Use mean or standard deviation to get a focus value for the line.  This value should be largest when the focus is best.

 

You might do okay by selecting lines from the image and analyzing them.  Analyzing the entire image works better, though.  This only measures the focus on one line, in the direction of the line.  I would probably pick three horizontal lines and three vertical lines and combined the edge values before calculating the standard deviation.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 6 of 14
(9,318 Views)

Bruce,

Not sure I understand.

When you say covert array to doubles do you mean intensity values?

what do you mean rotate the the array by one value?

Is it best to use the average value or the SD value?

 

Thanks.

0 Kudos
Message 7 of 14
(9,312 Views)
Solution
Accepted by topic author Jimmy01

Convert the image to an array using IMAQ ImageToArray.

 

Extract one row or line of the array using Index Array.  Assuming your image is U8, these will be U8 values.

 

Use numeric conversion To Double to convert the array to DBL values.

 

Use Rotate 1D Array with an shift of 1 to rotate the array.

 

Subtract the rotated array from the unrotated array.

 

Use Delete from Array to remove first element of array.  This is the difference between the first and last elements, which is unwanted.

 

Use absolute value to convert array to all positive values.

 

Use mean or standard deviation to measure the focus.  I usually have better results with standard deviation, but sometimes mean gives good results also.

 

Bruce

Bruce Ammons
Ammons Engineering
Message 8 of 14
(9,305 Views)

Thanks Bruce,

 

Looks like that might work after trying it, but could you explain this procedure in a little more detail because i dont understand how this procedure indicates how the image is in focus? Are the U8 values basically intensity values?

 

Thanks.

 

0 Kudos
Message 9 of 14
(9,290 Views)

The U8 values are the intensity values of the image.  By rotating the line and subtracting, you get the difference in intensity for adjacent pixels.  In a focused image, the change at an edge will be large and quick.  In an unfocused image, the intensity will change over several pixels and will not be as intense.  This measures how strong the intensity changes at the edges are.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 10 of 14
(9,287 Views)