Auto-focus-dealing with sparse areas

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Auto-focus-dealing with sparse areas

PEARSON Matthew
Hi all,

We're trying to use the auto-focus feature to capture images across a whole cover glass at 40x mag oil immersion and find that it works well with the Outtafocus algorithm when the  cell density is high.  However when encountering sparse areas it seems to get lost and then struggles to regain focus when coming back to areas with cells.  No z device is assigned for the acquisition so the focus point is purely defined by the autofocus routine (and a single z plane is acquired).  We are using the create grid option for the imaging.  If anyone has any advice on a way around this or perhaps its just a difficult thing to do with low density samples.  I have advised the user that preparing new slides with higher density may help.

Also it would be useful if there was a way to see a log of what the autofocus is doing mainly in terms of z positions its moving too and i don't think the core log captures this information?

Thanks for the advice,

Matt


--
Matt Pearson
Microscopy Facility
MRC Human Genetics Unit
Institute of Genetics and Molecular Medicine (IGMM)
University of Edinburgh
Crewe Road
EH4 2XU





The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Auto-focus-dealing with sparse areas

JonD
Administrator
Hi Matt,


PEARSON Matthew wrote
> We're trying to use the auto-focus feature to capture images across a
> whole cover glass at 40x mag oil immersion and find that it works well
> with the Outtafocus algorithm when the  cell density is high.  However
> when encountering sparse areas it seems to get lost and then struggles to
> regain focus when coming back to areas with cells ... If anyone has any
> advice on a way around this or perhaps its just a difficult thing to do
> with low density samples.  I have advised the user that preparing new
> slides with higher density may help.

Two ideas, not sure how useful they are:

Can you tell beforehand whether you are looking at a sparse or dense area
and only run autofocus when you are in a dense area?  

Maybe the OughtaFocus code could decide whether it "significantly" improved
the focus, and if not then it could restore the original Z position.
Brainstorming a possible implementation: define an improvement metric such
as the ratio of final to original focus score, normalized by the Z distance
moved.  After running, compute the metric and compare it with a user-set
threshold to decide whether to keep the new focus position or restore the
old one.  This obvious requires edits to the OughtaFocus code and you'd need
to be careful to keep existing functionality the same.



PEARSON Matthew wrote
> Also it would be useful if there was a way to see a log of what the
> autofocus is doing mainly in terms of z positions its moving too and i
> don't think the core log captures this information?

You might try enabling debug logging.  Looking at the source code there is
definitely some logging that goes on.

OughtaFocus uses Brent optimization (from Apache Commons Math library).  At
one point I considered augmenting the existing code to allow other
approaches, e.g. taking a stack of images, scoring each of them, and fitting
the scores to a Gaussian to find the optimal focus.  In the end I
implemented my approach separately in a plugin which scores the images using
the OughtaFocus algorithms (calling computeScore()) but handling the rest of
the functionality itself.

Jon

-------------------------------------------
Jon Daniels
Applied Scientific Instrumentation
29391 West Enid Rd, Eugene, OR 97402
Phone: (541) 461-8181 x118
-------------------------------------------



--
Sent from: http://micro-manager.3463995.n2.nabble.com/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Auto-focus-dealing with sparse areas

nathalieqbb@gmail.com
Hi Matt,

Hi,

If the autofocus takes into account only the middle of the frame and there are no cells there, the procedure will not work. One way around if you have access to the code is to do the autofocus on initially chosen dense areas and extrapolate the deviation to the rest of the slide.
Nathalie

On Wed, Sep 6, 2017 at 8:55 PM, JonD <[hidden email]> wrote:
Hi Matt,


PEARSON Matthew wrote
> We're trying to use the auto-focus feature to capture images across a
> whole cover glass at 40x mag oil immersion and find that it works well
> with the Outtafocus algorithm when the  cell density is high.  However
> when encountering sparse areas it seems to get lost and then struggles to
> regain focus when coming back to areas with cells ... If anyone has any
> advice on a way around this or perhaps its just a difficult thing to do
> with low density samples.  I have advised the user that preparing new
> slides with higher density may help.

Two ideas, not sure how useful they are:

Can you tell beforehand whether you are looking at a sparse or dense area
and only run autofocus when you are in a dense area?

Maybe the OughtaFocus code could decide whether it "significantly" improved
the focus, and if not then it could restore the original Z position.
Brainstorming a possible implementation: define an improvement metric such
as the ratio of final to original focus score, normalized by the Z distance
moved.  After running, compute the metric and compare it with a user-set
threshold to decide whether to keep the new focus position or restore the
old one.  This obvious requires edits to the OughtaFocus code and you'd need
to be careful to keep existing functionality the same.



PEARSON Matthew wrote
> Also it would be useful if there was a way to see a log of what the
> autofocus is doing mainly in terms of z positions its moving too and i
> don't think the core log captures this information?

You might try enabling debug logging.  Looking at the source code there is
definitely some logging that goes on.

OughtaFocus uses Brent optimization (from Apache Commons Math library).  At
one point I considered augmenting the existing code to allow other
approaches, e.g. taking a stack of images, scoring each of them, and fitting
the scores to a Gaussian to find the optimal focus.  In the end I
implemented my approach separately in a plugin which scores the images using
the OughtaFocus algorithms (calling computeScore()) but handling the rest of
the functionality itself.

Jon

-------------------------------------------
Jon Daniels
Applied Scientific Instrumentation
29391 West Enid Rd, Eugene, OR 97402
Phone: <a href="tel:%28541%29%20461-8181%20x118" value="+15414618181">(541) 461-8181 x118
-------------------------------------------



--
Sent from: http://micro-manager.3463995.n2.nabble.com/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general



--

Prof. Nathalie Q. Balaban

Racah Institute of Physics

The Hebrew University

Jerusalem, 91904, Israel

Phone: +972-2-6585400 ; Fax: +972-2-6585474

Lab website: http://bio-site.phys.huji.ac.il/


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Auto-focus-dealing with sparse areas

BenjaminPelz
In reply to this post by JonD
Hi Matt,

I was facing a similar problem when I was scanning over an area where large
parts were empty. The OughtaFocus started drifting in one z-direction and
when the scan reached an area with signal again it was already outside of
the scan range.
To prevent this from happening I changed the OughtaFocus code similar to
what Jon was suggesting:

JonD wrote

> Maybe the OughtaFocus code could decide whether it "significantly"
> improved
> the focus, and if not then it could restore the original Z position.
> Brainstorming a possible implementation: define an improvement metric such
> as the ratio of final to original focus score, normalized by the Z
> distance
> moved.  After running, compute the metric and compare it with a user-set
> threshold to decide whether to keep the new focus position or restore the
> old one.  This obvious requires edits to the OughtaFocus code and you'd
> need
> to be careful to keep existing functionality the same.

However, it's not as sophisticated as Jon proposed. I simply defined a score
threshold and when the best focus score is not above the threshold he will
keep the original z-position. It works quite well for me. However, one has
to define the score threshold which will probably be different under
different imaging conditions. But so far when I image similar samples I
don't have to change the threshold.
The focus scores are normally logged in the corelog so you can get an idea
what a good threshold could be.

Best
Ben




--
Sent from: http://micro-manager.3463995.n2.nabble.com/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general