OSCR

Real-time robust autofocus method enabling sustained intravital scanning light field imaging.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

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

  1. # Copyright (C) 2026 Yuedi Wang
  2. #
  3. # This file is part of AFsLF.
  4. #
  5. # AFsLF is free software: you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License version 2
  7. # as published by the Free Software Foundation.
  8. #
  9. # AFsLF is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY. See the LICENSE file for details.
  11. #
  12. # SPDX-License-Identifier: GPL-2.0-only
  13. import tifffile
  14. import numpy as np
  15. import pickle
  16. import cv2
  17. def distort_model(params, x, y):
  18. fx, fy, cx, cy, k1, k2, k3, p1, p2 = params
  19. matrix = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]])
  20. objpoints = np.concatenate((x[:, np.newaxis], y[:, np.newaxis], np.ones_like(y[:, np.newaxis])), axis=1)
  21. objpoints_rotated = np.matmul(objpoints, matrix)
  22. objpoints_projected = objpoints_rotated[:, :2] / (objpoints_rotated[:, 2:] + 1e-17)
  23. shift = objpoints_projected - np.array([cx, cy])
  24. x_shifted = shift[:, 0]
  25. y_shifted = shift[:, 1]
  26. r2 = x_shifted**2 + y_shifted**2
  27. 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
  28. 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
  29. return x_distorted, y_distorted
  30. def undistort_coor(params):
  31. H, W = (10748, 14304)
  32. gty, gtx = np.mgrid[:H, :W]
  33. gtxy = np.c_[gtx.ravel(), gty.ravel()]
  34. x_undistorted, y_undistorted = distort_model(params['inv_undistort'], (gtxy[:,0]-W//2)/100, (gtxy[:,1]-H//2)/100)
  35. x_undistorted = x_undistorted*100 + W//2
  36. y_undistorted = y_undistorted*100 + H//2
  37. return x_undistorted, y_undistorted
  38. def merge(wigner, group_mode, nshift=3):
  39. '''
  40. input:
  41. wigner: ( 180, ny_2, nx_2), dtype=torch.tensor
  42. output:
  43. merge_wigner: (172(20), ny_2*nshift, nx_2*nshift)
  44. '''
  45. order = [6, 5, 4, 7, 8, 3, 0, 1, 2]
  46. n, h, w = wigner.shape
  47. if group_mode == 1:
  48. merged_wigner = np.zeros([n - nshift**2 + 1, h*nshift, w*nshift])
  49. for i in range(merged_wigner.shape[0]):
  50. wigner_tmp = wigner[i:i + nshift**2]
  51. wigner_tmp = np.roll(wigner_tmp, i%nshift**2, 0)
  52. merged_wigner[i] = wigner_tmp[order].reshape(nshift, nshift, h, w).transpose(2, 0, 3, 1).reshape(h*nshift, w*nshift)
  53. else:
  54. merged_wigner = np.zeros([n//nshift**2, h*nshift, w*nshift])
  55. for i in range(merged_wigner.shape[0]):
  56. wigner_tmp = wigner[i * nshift**2:(i + 1) * nshift**2]
  57. merged_wigner[i] = wigner_tmp[order].reshape(nshift, nshift, h, w).transpose(2, 0, 3, 1).reshape(h*nshift, w*nshift)
  58. return merged_wigner
  59. def register_ecc(img1, img2):
  60. warp_matrix = np.eye(2, 3, dtype=np.float32)
  61. criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_COUNT, 100, 1e-6)
  62. cc, warp_matrix = cv2.findTransformECC(img2, img1, warp_matrix, cv2.MOTION_TRANSLATION, criteria)
  63. xshift = warp_matrix[0, 2]
  64. yshift = warp_matrix[1, 2]
  65. return yshift, xshift
  66. if __name__ == '__main__':
  67. H, W, centerX, centerY = 10748, 14304, 7151, 5373
  68. crop_H, crop_W = 1995, 1995
  69. kk=1#kk is the parameter KK is a pre-corrected parameter associated with system parameters.
  70. grid_x = np.arange(centerX-crop_W//2+7, centerX+crop_W//2+1, 15, dtype=np.int16)
  71. grid_y = np.arange(centerY-crop_H//2+7, centerY+crop_H//2+1, 15, dtype=np.int16)
  72. gtx, gty = np.meshgrid(grid_x, grid_y)
  73. gtxy = np.c_[gtx.ravel(), gty.ravel()]
  74. with open("./undistort_params_dict_points_240620.pkl", 'rb') as file:
  75. params = pickle.load(file)
  76. x_undistorted, y_undistorted = distort_model(params['inv_undistort'], (gtxy[:,0]-W//2)/100, (gtxy[:,1]-H//2)/100)
  77. x_undistorted = np.round(x_undistorted*100 + W//2).astype(np.int16)
  78. y_undistorted = np.round(y_undistorted*100 + H//2).astype(np.int16)
  79. start_x = centerX-2415//2
  80. start_y = centerY-2415//2
  81. x_undistorted -= start_x
  82. y_undistorted -= start_y
  83. with open("output_fft.txt", "w") as f:
  84. for i in range(0, 25):
  85. raw_path = f"Y:/C2/B18_{i}.tiff"
  86. lf = tifffile.imread(raw_path)
  87. wdf0 = lf[:, y_undistorted, x_undistorted-2].reshape(lf.shape[0], 133, 133)
  88. wdf1 = lf[:, y_undistorted, x_undistorted+2].reshape(lf.shape[0], 133, 133)
  89. merged_wdf_0 = merge(wdf0, 0).astype(np.float32)
  90. merged_wdf_1 = merge(wdf1, 0).astype(np.float32)
  91. for frame in range(len(merged_wdf_0)):
  92. yshift, xshift = register_ecc(merged_wdf_0[frame], merged_wdf_1[frame])
  93. fractor_X = kk
  94. defocus_x = xshift / fractor_X
  95. print('frame:', frame+i*20, 'yshift:', yshift, ', xshift:', xshift, ', defocus_x:', defocus_x)
  96. f.write(f"{defocus_x}\n")

autofocus_valid.py at commit 166cfc6, under GPL-2.0 · at the source

Overview

Authors: Yuedi Wang1, Jingyao Wu2,3, Jiamin Wu3,4,5, Yuan Li3, Wenjin Lv6, Fangfei Yu6,7, Jun Yan6, Zhi Lu8, Yi Yang6,9,10,11, Qionghai Dai3,5
  1. School of Information and Communication Engineering, Communication University of China, Beijing, China
  2. Artificial Intelligence Institute, China Academy of Information and Communications Technology, Beijing, China
  3. Department of Automation, Tsinghua University, Beijing, China
  4. IDG/McGovern Institute for Brain Research, Tsinghua University, Beijing, China
  5. Institute for Brain and Cognitive Sciences, Tsinghua University, Beijing, China
  6. Zhejiang Hehu Technology, Hangzhou, China
  7. School of Communication Engineering, Hangzhou Dianzi University, Hangzhou, China
  8. Department of Psychological and Cognitive Sciences, Tsinghua University, Beijing, China
  9. Hangzhou Innovation Institute, Beihang University, Hangzhou, China
  10. School of Reliability and Systems Engineering, Beihang University, Beijing, China
  11. Tianmushan Laboratory, Hangzhou, China
Journal: Nature communications, volume 17, issue 1, article 8105
Dates: received 18 November 2025; accepted 19 June 2026; published online 29 June 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41467-026-74976-z · PMID 42373656 · PMCID PMC13458141 · OpenAlex W7166510692
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: histology / microscopy (modality), mouse (organism)
Methods: Evoked potentials, Physiology & signal measures
Keywords: Microscopy, Imaging
MeSH: Imaging, Three-Dimensional*, Intravital Microscopy*, Animals, Brain, Liver, Mice (* major topic)
Topic: Digital Holography and Microscopy (Atomic and Molecular Physics, and Optics, Physics and Astronomy), according to OpenAlex
Funding: Young Scientists Fund; Fundamental Research Funds for the Central Universities
Citations: not cited yet (Europe PMC); 46 references in the paper

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

License: GPL-2.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Commit: 166cfc6a61d169ae2a81a882177d05eff95eeca2, 14 May 2026
Languages: Python (1)
Size: 13 files, 1 script
Software Heritage: not archived
Found in: “Code availability”
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (1 file), OpenCV (1 file), tifffile (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers
  • 27 September 2026: the link answers
3 files

Zenodo 20695290

License: GPL-2.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: “Code availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (1 file), OpenCV (1 file), tifffile (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
  • 27 September 2026: the link answers (HTTP 200)
3 files
At the source:

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:

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

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:

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://doi.org/10.1038/s41467-026-74976-z

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/s41467-026-74976-z},
url = {https://doi.org/10.1038/s41467-026-74976-z},
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/06/29
VL - 17
IS - 1
SP - 8105
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/s41467-026-74976-z
UR - https://doi.org/10.1038/s41467-026-74976-z
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41467-026-74976-z",
"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": "Nat Commun",
"volume": "17",
"issue": "1",
"page": "8105",
"DOI": "10.1038/s41467-026-74976-z",
"PMID": "42373656",
"PMCID": "PMC13458141",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41467-026-74976-z",
"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 communications
In 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 methods
In 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 optics
In 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 communications
In 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: eLife
In common: tifffile, OpenCV, NumPy, 1 reference
[6] doi:10.1038/s41467-026-72437-1 [code]
High-speed whole-brain imaging in Drosophila.
Journal: Nature communications
In 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 reports
In 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 methods
In 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: eLife
In 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: Neuroinformatics
In 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.

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.