Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Greetings,

I am new to C-sharp and I am trying to implement an auto focus setup on a digital microscope. I plan to have the camera on a small axis and have the camera take a couple of pictures at different distances. I would like the program to pick to picture that has the highest contrast(the least blurred picture). While researching this topic I found out there are several ways of doing this such as the FFT, phase measurement, and contrast measurement. I would like to use the contrast measurement method and just pick the picture with the highest contrast but I could not find any information on implementing that in Visual C#. Does anyone have any ideas as to how I could resolve this issue?

Thank you,
John K
Posted
Comments
Richard C Bishop 17-May-13 11:47am    
You will need to consult the documentation provided by the manufacturer of the device you are using.
Sergey Alexandrovich Kryukov 17-May-13 13:55pm    
This is not really related to the device; it should be done when the image is already delivered. Please see my answer.
—SA
Richard C Bishop 17-May-13 13:59pm    
Indeed. After re-reading it, it is device independent. Thank you for the clarification.
Sergey Alexandrovich Kryukov 17-May-13 14:05pm    
Sure. Note that OP was able to solve the problem, accepted my solution.
The problem is really interesting, come to think about; please see some more comments below.
—SA
Richard C Bishop 17-May-13 14:33pm    
Nice work! As usual.

1 solution

First of all, forget the PictureBox. It is totally irrelevant to image, and especially to its measurement. As this is a usual mistake, please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

The image is the bitmap, not the control.

To get all information from an image you need to use System.Drawing.Bitmap.LockBits:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^].

Better yet, I would recommend well-known open-source AForge.Net library:
http://en.wikipedia.org/wiki/AForge.NET[^],
http://www.aforgenet.com/[^].

See also the CodeProject articles by Andrew Kirillov, the author of AForge.Net: http://www.codeproject.com/Articles/Andrew-Kirillov#articles[^].

—SA
 
Share this answer
 
Comments
Member 9927463 17-May-13 13:44pm    
Thank you. I was able to use the standard deviation calculation as some sort of way to tell which picture is more blurry
Sergey Alexandrovich Kryukov 17-May-13 13:54pm    
Great; you are very welcome.
Good luck, call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900