-
Notifications
You must be signed in to change notification settings - Fork 1
Refactorings #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactorings #29
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
d69c5e6
Add docstrings to t1_maps/utils.py
finsberg 676edad
Add tests for t1_maps/utils.py
finsberg bdb8248
Add another function for comparing arrays
finsberg f01ecc6
Add tests for t1 to r1
finsberg 2baf833
Add more docstrings in t1_to_r1
finsberg 5c47ddc
Fix failing test
finsberg 8921a4e
Add script for generating test data from gonzo
finsberg ba4772b
Fix deprecated argument in scikit-image
finsberg 35e429d
Add tests for dicom
finsberg a877de2
Refactor stats
finsberg ee07b31
Restructure t1 maps
finsberg 890a96f
Update docs
finsberg e482b18
Separate concentration and r1
finsberg 55cb213
More restructuring
finsberg cab0e07
Add cli
finsberg c3dcdac
Add documentation
finsberg fe4cf7f
Remove .flake8 file
finsberg e7b429d
Update README
finsberg 342ece8
Start adding better logging
finsberg 217641b
More logging
finsberg 11d4258
Refactor masks - and add tests
finsberg d752c9e
Add seed to test
finsberg ecbdfe5
More logging
finsberg 922f207
Add suggestions from Cecile
finsberg 772c1ba
Fix more logging and add gonzo commands
finsberg d75dd1e
Run isort
finsberg 587e379
More docs
finsberg 7774535
Refactor stats
finsberg e5d57dc
Refactor segmentation
finsberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- | ||
| jupytext: | ||
| formats: md:myst | ||
| text_representation: | ||
| extension: .md | ||
| format_name: myst | ||
| kernelspec: | ||
| display_name: Python 3 | ||
| language: python | ||
| name: python3 | ||
| --- | ||
| # Concentration Mapping | ||
|
|
||
| The Concentration module calculates the spatial distribution of a contrast agent (like gadobutrol) in the brain. | ||
|
|
||
| Concentration $C$ can be estimated voxel-wise from longitudinal relaxation data comparing a post-contrast session to a pre-contrast (baseline) session. mritk supports two calculation pathways depending on whether you are working with $T_1$ times or $R_1$ rates (see R1 Maps). | ||
|
|
||
| $$\frac{1}{T_1} = \frac{1}{T_{10}} + r_1 C \quad \implies \quad C = \frac{1}{r_1} \left(R_1 - R_{10}\right)$$ | ||
|
|
||
| where $r_1$ is the relaxivity of the contrast agent (default: 3.2 to 4.5 $\text{s}^{-1}\text{mmol}^{-1}$). | ||
|
|
||
| ## Pipeline Overview | ||
|
|
||
| ```{mermaid} | ||
| graph TD | ||
| A[Pre-Contrast Hybrid T1] -->|T1 method| C{Compute Concentration} | ||
| B[Post-Contrast Hybrid T1] -->|T1 method| C | ||
|
|
||
| A2[Pre-Contrast R1] -->|R1 method| C | ||
| B2[Post-Contrast R1] -->|R1 method| C | ||
|
|
||
| M[Brain/Intracranial Mask] -.->|Optional| C | ||
|
|
||
| C --> D(Tracer Concentration Map NIfTI) | ||
| ``` | ||
|
|
||
| ## Commands | ||
|
|
||
| ```{code-cell} shell | ||
| !mritk concentration --help | ||
| ``` | ||
|
|
||
|
|
||
| ### 1. From $T_1$ Maps (t1) | ||
|
|
||
| Calculates concentration directly from $T_1$ maps (in milliseconds). The command handles the inversion safely and avoids division-by-zero errors for background voxels. | ||
|
|
||
| ```{code-cell} shell | ||
| !mritk concentration t1 --help | ||
| ``` | ||
|
|
||
| #### Example Command | ||
|
|
||
| ```shell | ||
| mritk concentration t1 -i path/to/post_t1.nii.gz -r path/to/pre_t1.nii.gz -o path/to/concentration.nii.gz --r1 0.0045 --mask path/to/intracranial_mask.nii.gz | ||
| ``` | ||
|
|
||
| Gonzo: | ||
|
|
||
| ```shell | ||
| mritk concentration t1 \ | ||
| -i gonzo/mri-processed/mri_processed_data/sub-01/T1maps/sub-01_ses-02_T1map_hybrid.nii.gz \ | ||
| -r gonzo/mri-processed/mri_processed_data/sub-01/T1maps/sub-01_ses-01_T1map_hybrid.nii.gz \ | ||
| -o sub-01_ses-02_concentration.nii.gz \ | ||
| --r1 0.0032 \ | ||
| --mask gonzo/mri-processed/mri_processed_data/sub-01/segmentations/sub-01_seg-intracranial_binary.nii.gz | ||
| ``` | ||
|
|
||
| mritk concentration t1 \ | ||
| -i new-test-data/mri-processed/mri_processed_data/sub-01/T1maps/sub-01_ses-02_T1map_hybrid.nii.gz \ | ||
| -r new-test-data/mri-processed/mri_processed_data/sub-01/T1maps/sub-01_ses-01_T1map_hybrid.nii.gz \ | ||
| -o sub-01_ses-02_concentration.nii.gz \ | ||
| --r1 0.0032 \ | ||
| --mask new-test-data/mri-processed/mri_processed_data/sub-01/segmentations/sub-01_seg-intracranial_binary.nii.gz | ||
|
|
||
| ### 2. From $R_1$ Maps (r1) | ||
|
|
||
| Calculates concentration from pre-computed $R_1$ maps. This is mathematically equivalent but slightly faster if $R_1$ maps are already available. | ||
|
|
||
| ```{code-cell} shell | ||
| !mritk concentration r1 --help | ||
| ``` | ||
|
|
||
| #### Example Command | ||
|
|
||
| ```shell | ||
| mritk concentration r1 -i path/to/post_r1.nii.gz -r path/to/pre_r1.nii.gz -o path/to/concentration.nii.gz --r1 0.0045 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| jupytext: | ||
| formats: md:myst | ||
| text_representation: | ||
| extension: .md | ||
| format_name: myst | ||
| kernelspec: | ||
| display_name: Python 3 | ||
| language: python | ||
| name: python3 | ||
| --- | ||
|
|
||
| # Hybrid $T_1$ Maps | ||
|
|
||
| To achieve accurate $T_1$ measurements across the entire brain space, mritk combines the Look-Locker (LL) and Mixed sequence $T_1$ maps into a single Hybrid map. | ||
|
|
||
| Look-Locker is used for short $T_1$ values (brain tissue and regions with high tracer concentrations). | ||
|
|
||
| Mixed Sequence is used for long $T_1$ values (CSF). | ||
|
|
||
| The hybrid command seamlessly merges the two images based on a user-defined threshold (default: 1500 ms) and a specific anatomical mask (typically a CSF mask). | ||
|
|
||
| ## Pipeline Overview | ||
|
|
||
| ```{mermaid} | ||
| graph LR | ||
| A(Look-Locker T1 Map) --> D{Hybrid Merge} | ||
| B(Mixed T1 Map) --> D | ||
| C(CSF Mask) --> D | ||
| D -->|Threshold > 1500ms| E(Hybrid T1 Map) | ||
| ``` | ||
|
|
||
| ## Command Usage | ||
|
|
||
|
|
||
| ```{code-cell} shell | ||
| !mritk hybrid --help | ||
| ``` | ||
|
|
||
| ## Example Command | ||
|
|
||
| ```shell | ||
| mritk hybrid -l path/to/ll_t1.nii.gz -m path/to/mixed_t1.nii.gz -c path/to/csf_mask.nii.gz -o path/to/hybrid_t1.nii.gz --threshold 1500.0 | ||
| ``` | ||
|
|
||
|
|
||
| Gonzo: | ||
|
|
||
| ```shell | ||
| mritk hybrid \ | ||
| -l gonzo/mri-processed/mri_processed_data/sub-01/registered/sub-01_ses-02_acq-looklocker_T1map_registered.nii.gz \ | ||
| -m gonzo/mri-processed/mri_processed_data/sub-01/registered/sub-01_ses-02_acq-mixed_T1map_registered.nii.gz \ | ||
| -c gonzo/mri-processed/mri_processed_data/sub-01/segmentations/sub-01_seg-csf_binary.nii.gz \ | ||
| -o sub-01_ses-02_T1map_hybrid.nii.gz \ | ||
| --threshold 1500 \ | ||
| --erode 1 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,30 @@ | ||
| --- | ||
| jupytext: | ||
| formats: md:myst | ||
| text_representation: | ||
| extension: .md | ||
| format_name: myst | ||
| kernelspec: | ||
| display_name: Python 3 | ||
| language: python | ||
| name: python3 | ||
| --- | ||
|
|
||
| # Info command | ||
|
|
||
| The `info` command allows you to quickly inspect the metadata of an MRI file. It displays the image shape, voxel size, data type, and the affine transformation matrix. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| mritk info <file_path> [OPTIONS] | ||
| ```{code-cell} shell | ||
| !mritk info --help | ||
| ``` | ||
|
|
||
| **Arguments:** | ||
| * `file`: Path to the file to display information about. | ||
| ### Example Command | ||
|
|
||
| **Options:** | ||
| * `--json`: Output information in JSON format. Useful for programmatic parsing. | ||
| ```bash | ||
| mritk info path/to/image.nii.gz | ||
| ``` | ||
|
|
||
|
|
||
|  |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.