Skip to content

feat: Add PhotonCT Walnuts dataset loader (#173) - #186

Open
Paramveersingh-S wants to merge 1 commit into
CambridgeCIA:mainfrom
Paramveersingh-S:feat/add-photonct-walnuts-dataset
Open

feat: Add PhotonCT Walnuts dataset loader (#173)#186
Paramveersingh-S wants to merge 1 commit into
CambridgeCIA:mainfrom
Paramveersingh-S:feat/add-photonct-walnuts-dataset

Conversation

@Paramveersingh-S

Copy link
Copy Markdown
Contributor

Summary

Introduces a native PyTorch Dataset loader for the newly published PhotonCT Walnuts dataset, expanding LION's support for spectral image reconstruction and deep learning data.

Resolves #173.

Problem

The newly released PhotonCT Walnuts dataset consists of high-resolution, multi-energy cone-beam CT scans (~296 GB total) stored in MATLAB's 16-bit unsigned integer .raw format. To train models within LION effectively, we need a native PyTorch integration that can read these projections iteratively, convert them from Fortran order (column-major) to standard PyTorch tensors, and properly normalize the data against the physical detector's flat-field air tables.

Solution

I have implemented PhotonCTWalnutDataset inside LION.data_loaders.photonct_walnuts, which mimics the structural simplicity of the existing original walnuts loader, while adding native spectral features and MATLAB-compatible data reshaping.

Key implementations:

  • Dynamic Energy Bins: Supports 'High', 'Low', and 'Total' energy bins. The Low bin is dynamically constructed from Total - High per the official physical data acquisition standard.
  • Air Correction (Flat-Fielding): Automatically loads the corresponding air_table_{bin}.raw and performs the native physical linearisation mapping (-log(proj) + log(airtable)).
  • Matrix Translation: Uses numpy.fromfile combined with .reshape(..., order='F') to correctly cast the MATLAB column-major data into contiguous C-order vectors for PyTorch compatibility.
  • Download Automation: Shipped an opt-in CLI script (download.py) to fetch the Calibration Table and individual walnuts incrementally from Zenodo, preventing disk saturation from the massive full dataset size.

Verification

  • Validated that the dataset loads properly and that the extracted shapes translate to [1, 505, 2063] tensor structures.
  • Verified that the __len__ matches the correct number of projections and the -log transformation avoids -inf domains via epsilon clamping (1e-6).

Resolves CambridgeCIA#173 by introducing a native PyTorch dataset loader for the PhotonCT Walnuts dataset.

Features:
- Added PhotonCTWalnutDataset supporting 'High', 'Low', and 'Total' energy bins.
- Integrated native flat-field air correction matching the calibration table.
- Reshapes projections correctly from column-major MATLAB format.
- Added download.py script to fetch walnuts selectively.
@AnderBiguri

Copy link
Copy Markdown
Member

Fantastic! this would need some testing, bear with me. @AndreaSainz , maybe you can test this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PhotonCT walnuts dataset

2 participants