Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5310771
just going to use niivue for this
bendhouseart Jul 3, 2025
d09c3a8
dynamically render preview
bendhouseart Jul 3, 2025
9f033ad
serving from across the host file system
bendhouseart Jul 14, 2025
bb4b42e
serves two files next to each other no overlap
bendhouseart Jul 15, 2025
5a0e918
comparison works for sure
bendhouseart Jul 15, 2025
d3db4ca
Merge branch 'dev' into rotating-heads
bendhouseart Jul 15, 2025
db02013
scan niivue preview added to full report
bendhouseart Jul 15, 2025
2036f81
creates reports, but the logic between comparing and datasets is to…
bendhouseart Jul 16, 2025
f9e8ca7
update avg and warp to occur during main pipeline
bendhouseart Jul 22, 2025
5cef427
generating svg's for comparison w/ good ole nipype
bendhouseart Jul 23, 2025
b40d360
made bare minimum report
bendhouseart Jul 25, 2025
d86ead9
renamed svg outputs
bendhouseart Jul 25, 2025
36d4947
happy with this, now with niivue shanigans
bendhouseart Jul 25, 2025
4580b40
rotating heads are back
bendhouseart Jul 25, 2025
70c7e0c
add entrypoint for qa reports
bendhouseart Jul 25, 2025
8572326
Merge branch 'dev' into simple-svg-report
bendhouseart Jul 25, 2025
1e5a00b
standardize commands
bendhouseart Jul 28, 2025
289fe36
cleaned up merge and moved html into template folder
bendhouseart Jul 28, 2025
b1fd5e3
Merge branch 'simple-svg-report' of github.com:openneuropet/petdeface…
bendhouseart Jul 28, 2025
4b68be2
refactored from defaced dir to bids dir to make qa usage more clear
bendhouseart Jul 28, 2025
d6ba06e
clean up toml and fix import
bendhouseart Jul 29, 2025
9a37927
Add missing --use_template_anat argument to fix AttributeError
bendhouseart Jul 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ options:
Options: 't1' (included T1w template), 'mni' (MNI template), or 'pet'
(averaged PET image).
--open_browser Open browser to show QA reports after completion
--qa-port QA_PORT Port for NIfTI preview server (default: 8000)
```

Working example usage:
Expand Down Expand Up @@ -106,6 +107,68 @@ Example usage with template anatomical:
petdeface /inputfolder /outputfolder --use_template_anat t1 --n_procs 16
```

### Quality Assessment (QA) Reports

PETdeface includes a comprehensive quality assessment system that generates reports to help validate defacing results. The QA system creates both SVG reports and interactive NIfTI viewers.

#### QA Report Location

QA reports are automatically generated in the input BIDS directory under `derivatives/petdeface/qa/`. This includes:
- SVG reports showing before/after defacing comparisons
- Interactive HTML viewers for 3D NIfTI visualization
- An index page linking to all available reports

#### Running QA Reports

**Automatic QA generation:**
```bash
petdeface /inputfolder /outputfolder --open_browser
```

**Manual QA generation using the separate QA tool:**
```bash
petdeface-qa /inputfolder --open-browser --start-server
```

#### NIfTI Preview Server

For 3D NIfTI visualization, PETdeface can start a local HTTP server to serve NIfTI files. This is required due to browser security restrictions.

**Start with server:**
```bash
petdeface-qa /inputfolder --start-server --open-browser
```

**Custom port:**
```bash
petdeface-qa /inputfolder --start-server --qa-port 8080
```

#### QA Tool Options

The `petdeface-qa` command provides the following options:

```bash
usage: petdeface-qa [-h] bids_dir [--output-dir OUTPUT_DIR]
[--open-browser] [--start-server] [--qa-port QA_PORT]

Generate SVG QA reports for PET deface workflow.

positional arguments:
bids_dir BIDS directory containing the defaced dataset (with derivatives/petdeface)

options:
-h, --help show this help message and exit
--output-dir OUTPUT_DIR, --output_dir OUTPUT_DIR
Output directory for HTML files (default: derivatives/petdeface/qa/)
--open-browser Open browser automatically
--start-server Start local HTTP server for NIfTI file access (required for NIfTI viewers)
--qa-port QA_PORT, --qa_port QA_PORT
Port for NIfTI preview server (default: 8000)
```

**Note**: The NIfTI preview server is required for 3D visualization due to browser CORS restrictions. Keep the terminal running while viewing NIfTI files.

### Docker Usage

Requirements:
Expand Down
8 changes: 8 additions & 0 deletions docs/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ petdeface.petdeface module
--------------------------

.. automodule:: petdeface.petdeface
:members:
:undoc-members:
:show-inheritance:

petdeface.qa module
------------------

.. automodule:: petdeface.qa
:members:
:undoc-members:
:show-inheritance:
75 changes: 74 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ options:
Options: 't1' (included T1w template), 'mni' (MNI template), or 'pet'
(averaged PET image).
--open_browser Following defacing this flag will open the browser to view the defacing results
--qa-port QA_PORT Port for NIfTI preview server (default: 8000)

Docker Based
------------
Expand Down Expand Up @@ -205,4 +206,76 @@ Example usage with template anatomical:

.. code-block:: bash

petdeface /inputfolder /outputfolder --use_template_anat t1 --n_procs 16
petdeface /inputfolder /outputfolder --use_template_anat t1 --n_procs 16

Quality Assessment (QA) Reports
------------------------------

PETdeface includes a comprehensive quality assessment system that generates reports to help validate defacing results. The QA system creates both SVG reports and interactive NIfTI viewers.

QA Report Location
~~~~~~~~~~~~~~~~~

QA reports are automatically generated in the input BIDS directory under ``derivatives/petdeface/qa/``. This includes:

- SVG reports showing before/after defacing comparisons
- Interactive HTML viewers for 3D NIfTI visualization
- An index page linking to all available reports

Running QA Reports
~~~~~~~~~~~~~~~~~

**Automatic QA generation:**

.. code-block:: bash

petdeface /inputfolder /outputfolder --open_browser

**Manual QA generation using the separate QA tool:**

.. code-block:: bash

petdeface-qa /inputfolder --open-browser --start-server

NIfTI Preview Server
~~~~~~~~~~~~~~~~~~~

For 3D NIfTI visualization, PETdeface can start a local HTTP server to serve NIfTI files. This is required due to browser security restrictions.

**Start with server:**

.. code-block:: bash

petdeface-qa /inputfolder --start-server --open-browser

**Custom port:**

.. code-block:: bash

petdeface-qa /inputfolder --start-server --qa-port 8080

QA Tool Options
~~~~~~~~~~~~~~

The ``petdeface-qa`` command provides the following options:

.. code-block:: bash

usage: petdeface-qa [-h] bids_dir [--output-dir OUTPUT_DIR]
[--open-browser] [--start-server] [--qa-port QA_PORT]

Generate SVG QA reports for PET deface workflow.

positional arguments:
bids_dir BIDS directory containing the defaced dataset (with derivatives/petdeface)

options:
-h, --help show this help message and exit
--output-dir OUTPUT_DIR, --output_dir OUTPUT_DIR
Output directory for HTML files (default: derivatives/petdeface/qa/)
--open-browser Open browser automatically
--start-server Start local HTTP server for NIfTI file access (required for NIfTI viewers)
--qa-port QA_PORT, --qa_port QA_PORT
Port for NIfTI preview server (default: 8000)

**Note**: The NIfTI preview server is required for 3D visualization due to browser CORS restrictions. Keep the terminal running while viewing NIfTI files.
20 changes: 17 additions & 3 deletions petdeface/pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

class WeightedAverageInputSpec(BaseInterfaceInputSpec):
pet_file = File(exists=True, desc="Dynamic PET", mandatory=True)
sidecar_file = File(
exists=True,
desc="Optional sidecar JSON file for timing info. If not provided, uses sidecar from pet_file.",
mandatory=False,
)


class WeightedAverageOutputSpec(TraitedSpec):
Expand Down Expand Up @@ -47,9 +52,18 @@ def _run_interface(self, runtime):
img = nib.load(pet_file)
data = img.get_fdata()

meta = ReadSidecarJSON(
in_file=pet_file, bids_dir=bids_dir, bids_validate=False
).run()
# Use optional sidecar file if provided, otherwise use pet_file's sidecar
if hasattr(self.inputs, "sidecar_file") and self.inputs.sidecar_file:
sidecar_file = self.inputs.sidecar_file
sidecar_bids_dir = os.path.dirname(sidecar_file)
meta = ReadSidecarJSON(
in_file=sidecar_file, bids_dir=sidecar_bids_dir, bids_validate=False
).run()
else:
# Default behavior: use pet_file's sidecar
meta = ReadSidecarJSON(
in_file=pet_file, bids_dir=bids_dir, bids_validate=False
).run()

frames_start = np.array(meta.outputs.out_dict["FrameTimesStart"])
frames_duration = np.array(meta.outputs.out_dict["FrameDuration"])
Expand Down
Loading