Real-time robust autofocus method enabling sustained intravital scanning light field imaging.
Paper
Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 112 lines · 4.8 KB · GPL-2.0
- # Copyright (C) 2026 Yuedi Wang
- #
- # This file is part of AFsLF.
- #
- # AFsLF is free software: you can redistribute it and/or modify it
- # under the terms of the GNU General Public License version 2
- # as published by the Free Software Foundation.
- #
- # AFsLF is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY. See the LICENSE file for details.
- #
- # SPDX-License-Identifier: GPL-2.0-only
- import tifffile
- import numpy as np
- import pickle
- import cv2
- def distort_model(params, x, y):
- fx, fy, cx, cy, k1, k2, k3, p1, p2 = params
- matrix = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]])
- objpoints = np.concatenate((x[:, np.newaxis], y[:, np.newaxis], np.ones_like(y[:, np.newaxis])), axis=1)
- objpoints_rotated = np.matmul(objpoints, matrix)
- objpoints_projected = objpoints_rotated[:, :2] / (objpoints_rotated[:, 2:] + 1e-17)
- shift = objpoints_projected - np.array([cx, cy])
- x_shifted = shift[:, 0]
- y_shifted = shift[:, 1]
- r2 = x_shifted**2 + y_shifted**2
- x_distorted = x_shifted * (1 + k1*r2 + k2*r2**2 + k3*r2**3) + 2*p1*x_shifted*y_shifted + p2*(r2 + 2*x_shifted**2) + cx
- y_distorted = y_shifted * (1 + k1*r2 + k2*r2**2 + k3*r2**3) + p1*(r2 + 2*y_shifted**2) + 2*p2*x_shifted*y_shifted + cy
- return x_distorted, y_distorted
- def undistort_coor(params):
- H, W = (10748, 14304)
- gty, gtx = np.mgrid[:H, :W]
- gtxy = np.c_[gtx.ravel(), gty.ravel()]
- x_undistorted, y_undistorted = distort_model(params['inv_undistort'], (gtxy[:,0]-W//2)/100, (gtxy[:,1]-H//2)/100)
- x_undistorted = x_undistorted*100 + W//2
- y_undistorted = y_undistorted*100 + H//2
- return x_undistorted, y_undistorted
- def merge(wigner, group_mode, nshift=3):
- '''
- input:
- wigner: ( 180, ny_2, nx_2), dtype=torch.tensor
- output:
- merge_wigner: (172(20), ny_2*nshift, nx_2*nshift)
- '''
- order = [6, 5, 4, 7, 8, 3, 0, 1, 2]
- n, h, w = wigner.shape
- if group_mode == 1:
- merged_wigner = np.zeros([n - nshift**2 + 1, h*nshift, w*nshift])
- for i in range(merged_wigner.shape[0]):
- wigner_tmp = wigner[i:i + nshift**2]
- wigner_tmp = np.roll(wigner_tmp, i%nshift**2, 0)
- merged_wigner[i] = wigner_tmp[order].reshape(nshift, nshift, h, w).transpose(2, 0, 3, 1).reshape(h*nshift, w*nshift)
- else:
- merged_wigner = np.zeros([n//nshift**2, h*nshift, w*nshift])
- for i in range(merged_wigner.shape[0]):
- wigner_tmp = wigner[i * nshift**2:(i + 1) * nshift**2]
- merged_wigner[i] = wigner_tmp[order].reshape(nshift, nshift, h, w).transpose(2, 0, 3, 1).reshape(h*nshift, w*nshift)
- return merged_wigner
- def register_ecc(img1, img2):
- warp_matrix = np.eye(2, 3, dtype=np.float32)
- criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_COUNT, 100, 1e-6)
- cc, warp_matrix = cv2.findTransformECC(img2, img1, warp_matrix, cv2.MOTION_TRANSLATION, criteria)
- xshift = warp_matrix[0, 2]
- yshift = warp_matrix[1, 2]
- return yshift, xshift
- if __name__ == '__main__':
- H, W, centerX, centerY = 10748, 14304, 7151, 5373
- crop_H, crop_W = 1995, 1995
- kk=1#kk is the parameter KK is a pre-corrected parameter associated with system parameters.
- grid_x = np.arange(centerX-crop_W//2+7, centerX+crop_W//2+1, 15, dtype=np.int16)
- grid_y = np.arange(centerY-crop_H//2+7, centerY+crop_H//2+1, 15, dtype=np.int16)
- gtx, gty = np.meshgrid(grid_x, grid_y)
- gtxy = np.c_[gtx.ravel(), gty.ravel()]
- with open("./undistort_params_dict_points_240620.pkl", 'rb') as file:
- params = pickle.load(file)
- x_undistorted, y_undistorted = distort_model(params['inv_undistort'], (gtxy[:,0]-W//2)/100, (gtxy[:,1]-H//2)/100)
- x_undistorted = np.round(x_undistorted*100 + W//2).astype(np.int16)
- y_undistorted = np.round(y_undistorted*100 + H//2).astype(np.int16)
- start_x = centerX-2415//2
- start_y = centerY-2415//2
- x_undistorted -= start_x
- y_undistorted -= start_y
- with open("output_fft.txt", "w") as f:
- for i in range(0, 25):
- raw_path = f"Y:/C2/B18_{i}.tiff"
- lf = tifffile.imread(raw_path)
- wdf0 = lf[:, y_undistorted, x_undistorted-2].reshape(lf.shape[0], 133, 133)
- wdf1 = lf[:, y_undistorted, x_undistorted+2].reshape(lf.shape[0], 133, 133)
- merged_wdf_0 = merge(wdf0, 0).astype(np.float32)
- merged_wdf_1 = merge(wdf1, 0).astype(np.float32)
- for frame in range(len(merged_wdf_0)):
- yshift, xshift = register_ecc(merged_wdf_0[frame], merged_wdf_1[frame])
- fractor_X = kk
- defocus_x = xshift / fractor_X
- print('frame:', frame+i*20, 'yshift:', yshift, ', xshift:', xshift, ', defocus_x:', defocus_x)
- f.write(f"{defocus_x}\n")
autofocus_valid.py at commit 166cfc6, under GPL-2.0 · at the source
Overview
- School of Information and Communication Engineering, Communication University of China, Beijing, China
- Artificial Intelligence Institute, China Academy of Information and Communications Technology, Beijing, China
- Department of Automation, Tsinghua University, Beijing, China
- IDG/McGovern Institute for Brain Research, Tsinghua University, Beijing, China
- Institute for Brain and Cognitive Sciences, Tsinghua University, Beijing, China
- Zhejiang Hehu Technology, Hangzhou, China
- School of Communication Engineering, Hangzhou Dianzi University, Hangzhou, China
- Department of Psychological and Cognitive Sciences, Tsinghua University, Beijing, China
- Hangzhou Innovation Institute, Beihang University, Hangzhou, China
- School of Reliability and Systems Engineering, Beihang University, Beijing, China
- Tianmushan Laboratory, Hangzhou, China
Abstract
The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.
Repositories
Its files are read in the Code ↔ Paper reader above.
yuedi-wang/AFsLF
166cfc6a61d169ae2a81a882177d05eff95eeca2, 14 May 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
3 files
- autofocus_valid.py, Python, 112 lines
- LICENSE, License, 339 lines
- README.md, Text, 219 lines
Zenodo 20695290
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
- 27 September 2026: the link answers (HTTP 200)
3 files
- autofocus_valid.py, Python, 112 lines
- LICENSE, License, 339 lines
- README.md, Text, 219 lines
Code availability statement
The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it points to the authors' code: yuedi-wang/
AFsLF , Zenodo 20695290
Read it in the paper: doi.org/10.1038/s41467-026-74976-z.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 2 scripts, each with its path and the digest of its content;
- no match between paragraphs and code yet;
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- zenodo:19660029, at Zenodo; found in “Data availability”
Code and data availability statement
The paper has a code and data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:
- it points to a dataset: Zenodo 19660029
- it points to the authors' code: yuedi-wang/
AFsLF , Zenodo 20695290
Read it in the paper: doi.org/10.1038/s41467-026-74976-z.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 2, 28 September 2026
- Funding: added Young Scientists Fund; Fundamental Research Funds for the Central Universities
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 10 authors, 2 keywords, 6 MeSH terms, 35 references.
Cite
This paper
Wang, Y., Wu, J., Wu, J., Li, Y., Lv, W., Yu, F., Yan, J., Lu, Z., Yang, Y., & Dai, Q. (2026). Real-time robust autofocus method enabling sustained intravital scanning light field imaging. Nature communications, 17(1), 8105. https://
BibTeX
@article{wang2026real,
author = {Wang, Yuedi and Wu, Jingyao and Wu, Jiamin and Li, Yuan and Lv, Wenjin and Yu, Fangfei and Yan, Jun and Lu, Zhi and Yang, Yi and Dai, Qionghai},
title = {{Real-time robust autofocus method enabling sustained intravital scanning light field imaging}},
journal = {Nature communications},
year = {2026},
month = jun,
volume = {17},
number = {1},
pages = {8105},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/
url = {https://
pmid = {42373656},
pmcid = {PMC13458141}
}
RIS
TY - JOUR
AU - Wang, Yuedi
AU - Wu, Jingyao
AU - Wu, Jiamin
AU - Li, Yuan
AU - Lv, Wenjin
AU - Yu, Fangfei
AU - Yan, Jun
AU - Lu, Zhi
AU - Yang, Yi
AU - Dai, Qionghai
TI - Real-time robust autofocus method enabling sustained intravital scanning light field imaging
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/
VL - 17
IS - 1
SP - 8105
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"type": "article-journal",
"title": "Real-time robust autofocus method enabling sustained intravital scanning light field imaging",
"container-title": "Nature communications",
"author": [
{
"family": "Wang",
"given": "Yuedi"
},
{
"family": "Wu",
"given": "Jingyao"
},
{
"family": "Wu",
"given": "Jiamin"
},
{
"family": "Li",
"given": "Yuan"
},
{
"family": "Lv",
"given": "Wenjin"
},
{
"family": "Yu",
"given": "Fangfei"
},
{
"family": "Yan",
"given": "Jun"
},
{
"family": "Lu",
"given": "Zhi"
},
{
"family": "Yang",
"given": "Yi"
},
{
"family": "Dai",
"given": "Qionghai"
}
],
"container-title-short":
"volume": "17",
"issue": "1",
"page": "8105",
"DOI": "10.1038/
"PMID": "42373656",
"PMCID": "PMC13458141",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
6,
29
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1038/s41592-025-02698-z [code]
- Physics-driven self-supervised learning for fast high-resolution robust 3D reconstruction of light-field microscopy.Journal: Nature methodsIn common: tifffile, NumPy, histology / microscopy, mouse, 13 references, 2 authors
- [2] doi:10.1038/s41587-024-02249-5 [code]
- Long-term intravital subcellular imaging with confocal scanning light-field microscopy.Journal: Nature biotechnologyIn common: histology / microscopy, mouse, 11 references, 2 authors
- [3] doi:10.1038/s41467-023-39860-0 [code]
- Large depth-of-field ultra-compact microscope by progressive optimization and deep learning.Journal: Nature communicationsIn common: tifffile, NumPy, histology / microscopy, 6 references, author Jiamin Wu
- [4] doi:10.1117/1.nph.9.4.041407
- Review on data analysis methods for mesoscale neural imaging <i>in vivo</
i>. Journal: NeurophotonicsIn common: 6 references, author Jiamin Wu - [5] doi:10.1038/s41587-022-01450-8 [code]
- Real-time denoising enables high-sensitivity fluorescence time-lapse imaging beyond the shot-noise limit.Journal: Nature biotechnologyIn common: tifffile, OpenCV, NumPy, histology / microscopy, mouse, 3 references, author Jiamin Wu
- [6] doi:10.1038/s41592-025-02886-x [code]
- CELLECT: contrastive embedding learning for large-scale efficient cell tracking.Journal: Nature methodsIn common: tifffile, NumPy, mouse, 4 references, author Jiamin Wu
- [7] doi:10.1038/s41592-023-01838-7 [code]
- Rapid detection of neurons in widefield calcium imaging datasets after training with synthetic data.Journal: Nature methodsIn common: tifffile, OpenCV, NumPy, histology / microscopy, mouse, 2 references, author Jiamin Wu
- [8] doi:10.1073/pnas.2510337122 [code]
- Light-field deep learning enables high-throughput, scattering-mitigated calcium imaging.Journal: Proceedings of the National Academy of Sciences of the United States of AmericaIn common: tifffile, NumPy, histology / microscopy, mouse, 5 references
- [9] doi:10.1038/s41467-024-48575-9 [code]
- Zero-shot learning enables instant denoising and super-resolution in optical fluorescence microscopy.Journal: Nature communicationsIn common: tifffile, OpenCV, NumPy, histology / microscopy, mouse, 1 reference, author Jiamin Wu
- [10] doi:10.1038/s43588-023-00568-2 [code]
- Spatial redundancy transformer for self-supervised fluorescence image denoising.Journal: Nature computational scienceIn common: tifffile, NumPy, histology / microscopy, 2 references, author Jiamin Wu
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 2 repositories of the authors' code, each at its verified commit and with its license, 2 scripts, and 0 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:25c74bf048e58630…
Add the badge to the code's README
If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.
Markdown
<!-- oscr-badge:start -->
[](https://openscicode.org/badge/doi/10.1038/s41467-026-74976-z)
<!-- oscr-badge:end -->reStructuredText
.. oscr-badge:start
.. image:: https://openscicode.org/badge/doi/10.1038/s41467-026-74976-z.svg
:target: https://openscicode.org/badge/doi/10.1038/s41467-026-74976-z
:alt: OSCR
.. oscr-badge:endHTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1038/s41467-026-74976-z"><img src="https://openscicode.org/badge/doi/10.1038/s41467-026-74976-z.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".
If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.
Report a mismatch between the code and the paper · Report a code error (signed in)
Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.
Report a reproduction failure (signed in)
Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
