Skip to main content

FenestRA: A Napari plugin for LSEC AFM Super-Resolution & Fenestration Analysis.

Project description

FenestRA Logo

FenestRA

Fenestration Resolution & Analysis Pipeline

Python Napari CUDA PyTorch run with conda run with docker run with apptainer/singularity

FenestRA is a custom Napari plugin built for the Advanced LSEC AFM Pipeline. It bridges the gap between interactive Napari features, legacy deep-learning upscale repositories via containerized backends, and state-of-the-art Cellpose instance segmentation.

By combining Deep Learning-based Super Resolution (HAT / SwinIR) with automated morphological analysis, FenestRA drastically simplifies the workflow of extracting robust physical porosity and fenestration morphology metrics directly from raw .jpk.qi-image files.


Features

  • Cross-Platform Container Engine: Seamlessly toggle between Docker (Windows / macOS) and Singularity / Apptainer (Linux / HPC) directly from the Napari UI. No code changes needed when switching platforms.
  • Hub-and-Spoke Deep Learning Architecture: Run legacy Python 3.8 dependent upscale models (HAT, SwinIR) asynchronously inside a container without freezing your modern Napari GUI.
  • Post-DL Image Enhancement: Optional CLAHE contrast equalization and Unsharp Masking applied directly to the Deep Learning output to sharpen fenestration edges before segmentation.
  • Native JPK Ingestion: Automatically reads native physical scale (nm / px) from .jpk.qi-image files using AFMReader.
  • Synchronized 4-Pane Analysis: Auto-generates a synchronized Napari viewer layout combining Raw, Upsampled, Mask, and Boundary Overlays natively.
  • Configurable CPU Fallback: Includes high-fidelity Python-based CLAHE and unsharp masking functions when DL inference isn't required.
  • Sub-cellular Quantification: Automatically calculates standard metrics (area, perimeter, equivalent diameter, eccentricity, porosity) with digital-to-physical size translations directly to .csv.
  • Batch Analysis: Process an entire folder of .jpk-qi-image files in one automated run. Produces a single consolidated .xlsx Excel file with metrics from all images, plus individual upsampled TIFFs and Cellpose mask TIFFs.

Installation

1. Requirements

  • Python 3.10+
  • An NVIDIA GPU with CUDA 12.4 drivers (recommended for DL inference)
  • Linux: Apptainer / Singularity
  • Windows / macOS: Docker Desktop

2. Create the Host Environment

Create a clean Anaconda environment optimized for Cellpose targeting CUDA 12.4:

conda create -n fenestra-env -c conda-forge python=3.10 numpy=1.26.4
conda activate fenestra-env

# Install base GUI tools, Napari, and core scientific dependencies
pip install "napari[all]" magicgui qtpy scipy scikit-image pandas tifffile "numpy<2" openpyxl

# Install PyTorch mapped explicitly to CUDA 12.4 to ensure GPU hardware acceleration works
pip install --index-url https://download.pytorch.org/whl/cu124 torch==2.4.0 torchvision==0.19.0

# Install Cellpose for fenestration instance segmentation
pip install cellpose

# Install AFMReader for handling raw JPK AFM metadata
pip install git+https://github.com/AFM-SPM/AFMReader.git

3. Install FenestRA

Clone this repository and install it in "editable" mode:

git clone https://github.com/LIVR-VUB/FenestRA.git
cd FenestRA
pip install -e .

4. Setup the Deep Learning Backend (Docker vs Singularity)

FenestRA runs its massive deep learning architectures completely independently from the modern Napari UI. You must compile the container engine based on your Operating System:

For Windows & macOS Users (Docker Desktop): Because Apple and Windows systems cannot securely install Singularity, we use Docker.

  1. Install Docker Desktop on your machine.
  2. Open a terminal and navigate to this repository's containers/ directory.
  3. Build the backend image (Windows/Mac users do NOT need sudo):
docker build -t livrvub/dl-upsampling:latest -f Dockerfile ..

(In Napari, select Docker from the Engine dropdown. No file browsing needed!)

For Native Linux Users (Singularity / Apptainer): Linux systems heavily restrict Docker permissions. For ultimate performance and hassle-free paths on Linux, use Apptainer/Singularity.

  1. Install Apptainer natively on your Linux distribution.
  2. Open a terminal and build the container using the provided definition recipe:
sudo apptainer build dl_upsampling.sif containers/dl_upsampling.def

(In Napari, select Singularity from the Engine dropdown, and use the ... button to select that .sif file!)


Usage

Single Image Analysis

  1. Activate your environment: conda activate fenestra-env
  2. Launch napari: napari
  3. Navigate to Plugins > FenestRA Pipeline to open the widget!
  4. Step 1 — Input Data: Load your *.jpk-qi-image file.
  5. Step 2 — Upsampling: Select a method (CLAHE, HAT, or SwinIR). For DL methods, specify the model .pth, choose your Engine (Docker or Singularity), and optionally enable "Apply Post-DL Sharpening" with adjustable Clip Limit and Unsharp parameters. Hit Run Upsampling.
  6. Step 3 — Segmentation: Configure Cellpose parameters (Diameter, Cellprob Threshold, Flow Threshold). Optionally load a custom Cellpose model. Hit Run Cellpose.
  7. Step 4 — Layout & Analysis: Click Arrange 4-Pane Grid for a synchronized review of Raw, Upsampled, Mask, and Overlay views. Click Quantify Fenestrations to export your CSV metrics.

Batch Analysis

  1. Configure your preferred upsampling method, model paths, and Cellpose parameters using the single-image sections above.
  2. Scroll down to Section 5 — Batch Analysis.
  3. Select an Input Directory containing your .jpk-qi-image files.
  4. Select an Output Directory where results will be saved.
  5. Click Run Batch. The status label will update in real-time showing progress (e.g., Processing 3/10: sample.jpk-qi-image).
  6. When complete, the output directory will contain:
    • batch_results.xlsx — Consolidated Excel file with metrics from all images (with Image_Name column).
    • <image_name>_upsampled.tif — Upsampled TIFF for each input image.
    • <image_name>_mask.tif — Cellpose segmentation mask for each input image.

Changelog

v0.2

  • Batch Analysis Module: New Section 5 in the Napari UI for processing entire folders of .jpk-qi-image files. Outputs a single consolidated .xlsx Excel file with fenestration metrics from all images, plus individual upsampled TIFFs and Cellpose mask TIFFs.
  • Post-DL Image Enhancement: Added an optional "Apply Post-DL Sharpening" checkbox that applies CLAHE contrast equalization and Unsharp Masking to the Deep Learning output before Cellpose segmentation.
  • UI Restructuring: Separated the Clip Limit / Unsharp Radius / Amount sliders into a shared post-processing group that is dynamically visible for both CLAHE and DL workflows.

v0.1

  • Cross-Platform Docker Support: Added a Dockerfile mirroring the Singularity .def environment. Users can now toggle between Docker and Singularity engines directly from the Napari UI.
  • Engine Toggle UI: New "Engine" dropdown in the Upsampling section. Selecting Docker shows a tag input; selecting Singularity shows a .sif file picker.
  • Container Recipes: Both Dockerfile and dl_upsampling.def are now bundled in the containers/ directory.
  • Cross-Platform README: Added installation instructions for Windows, macOS, and Linux users.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

napari_fenestra-0.2.1.tar.gz (74.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

napari_fenestra-0.2.1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file napari_fenestra-0.2.1.tar.gz.

File metadata

  • Download URL: napari_fenestra-0.2.1.tar.gz
  • Upload date:
  • Size: 74.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for napari_fenestra-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d5540fc94cc957261004b843cfe3d9beb49f077d21af1b594abf0c0b473f657e
MD5 120d0b1b27ed76cd7d1bee4e92a5b536
BLAKE2b-256 d4e2d692e5d928c7eec89a90b2eab9398be0541492141751167c18357e479dce

See more details on using hashes here.

File details

Details for the file napari_fenestra-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for napari_fenestra-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1d15216bdc4f4ee1dc4466e191f5c4c3b324af732db37fb4ff248a6248acdab
MD5 244df6b923c1a526428394e7b903545d
BLAKE2b-256 b108df39164f1270be395af6fbd4feb55fa5d49da66e112604481bd97e1b8c29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page