Real-time robust autofocus method enabling sustained intravital scanning light field imaging.
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: 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/s41467-026-72454-0 [code]
- Dynamic neuronal ensembles encode burst-suppression revealed by cortex-wide optical-electrical interfaces.Journal: Nature communicationsIn common: tifffile, OpenCV, NumPy, mouse, 1 reference, author Jiamin Wu
- [2] doi:10.1038/s41592-026-03179-7 [code]
- Voltage imaging of neurons distributed across entire brains of larval zebrafish.Journal: Nature methodsIn common: OpenCV, NumPy, histology / microscopy, 4 references
- [3] doi:10.1117/1.jbo.31.3.036002 [code]
- Improved 3D image reconstruction via deep-learning-based fusion of light-field microscopy and Fourier light-field microscopy images.Journal: Journal of biomedical opticsIn common: histology / microscopy, mouse, 4 references
- [4] doi:10.1038/s41467-026-73045-9 [code]
- Aberration-aware 3D localization microscopy via self-supervised neural-physics learning.Journal: Nature communicationsIn common: tifffile, OpenCV, NumPy, histology / microscopy, 1 reference
- [5] doi:10.7554/elife.100880 [code]
- An applicable and efficient retrograde monosynaptic circuit mapping tool for larval zebrafish.Journal: eLifeIn common: tifffile, OpenCV, NumPy, 1 reference
- [6] doi:10.1038/s41467-026-72437-1 [code]
- High-speed whole-brain imaging in Drosophila.Journal: Nature communicationsIn common: OpenCV, NumPy, 2 references
- [7] doi:10.1038/s41598-026-57519-w [code]
- Automated segmentation of neurons and spinal cord structures in immunofluorescence images using SpineDL.Journal: Scientific reportsIn common: tifffile, OpenCV, NumPy, histology / microscopy, mouse
- [8] doi:10.1016/j.crmeth.2026.101476 [code]
- Unsupervised deep learning enables blur-free resolution enhancement in two-photon microscopy.Journal: Cell reports methodsIn common: tifffile, OpenCV, NumPy, histology / microscopy, mouse
- [9] doi:10.7554/elife.110277 [code]
- Functional imaging of nine distinct neuronal populations under a miniscope in freely behaving animals.Journal: eLifeIn common: tifffile, OpenCV, NumPy, histology / microscopy, mouse
- [10] doi:10.1007/s12021-026-09815-z [code]
- BasNet: Attention U-Net-Based Automated Axon Segmentation in Bielschowsky Silver-Stained Histology.Journal: NeuroinformaticsIn common: tifffile, OpenCV, NumPy, histology / microscopy
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:de6ee837bcfb738c…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
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: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
