Skip to content
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

Add augmentation mri transforms #279

Merged
merged 37 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c686711
Add new transforms
georgeyiasemis Jun 5, 2024
c1dd9a5
Typing fix
georgeyiasemis Jun 5, 2024
357a680
Remove python 3.8 checks cause they keep failing
georgeyiasemis Jun 5, 2024
7cd2fa0
Try 3.10
georgeyiasemis Jun 5, 2024
6821dac
Try 3.10
georgeyiasemis Jun 5, 2024
309d515
Try 3.10
georgeyiasemis Jun 5, 2024
a9a7bb6
Try 3.10
georgeyiasemis Jun 5, 2024
6d34de5
Try 3.10
georgeyiasemis Jun 5, 2024
15bc1bb
Update tox.yml
georgeyiasemis Jun 6, 2024
fedef55
Update tox.yml
georgeyiasemis Jun 6, 2024
f59668d
Update setup.py
georgeyiasemis Jun 6, 2024
9a35a0f
Update setup.py
georgeyiasemis Jun 6, 2024
9bbdaff
Update setup.py
georgeyiasemis Jun 6, 2024
2d7ef73
Change py version
georgeyiasemis Jun 6, 2024
c6b4c0a
Change py version
georgeyiasemis Jun 6, 2024
fbad9e1
Add forgotten argument
georgeyiasemis Jun 6, 2024
2841215
Minor fix
georgeyiasemis Jun 6, 2024
e824db2
Minor fix
georgeyiasemis Jun 6, 2024
354a008
Update for codacy, add tests
georgeyiasemis Jun 6, 2024
fd08d06
Update for codacy, add tests
georgeyiasemis Jun 6, 2024
31c6cfa
Update pylint.yml
georgeyiasemis Jun 6, 2024
76d06f2
Update coverage.yml
georgeyiasemis Jun 13, 2024
531e35c
Update py version
georgeyiasemis Jun 13, 2024
bf813b9
Update py version
georgeyiasemis Jun 13, 2024
a8f70d4
Update versions
georgeyiasemis Jun 13, 2024
6fd3629
Typing
georgeyiasemis Jun 13, 2024
6716770
Update versions
georgeyiasemis Jun 13, 2024
8b9c4c6
Minor fix
georgeyiasemis Jun 13, 2024
e41f3b3
Revert back
georgeyiasemis Jun 23, 2024
e1290bc
New version (pip?) causes problems with cnp.int_t
georgeyiasemis Jun 24, 2024
6d118d6
Try int_t again
georgeyiasemis Jun 24, 2024
175371b
Try int64_t
georgeyiasemis Jun 24, 2024
716ea39
Typo
georgeyiasemis Jun 24, 2024
202dbaf
Deprecated np.product -> np.prod
georgeyiasemis Jun 24, 2024
341ceb7
Pylint failing
georgeyiasemis Jun 24, 2024
e50b77b
Pylint failing
georgeyiasemis Jun 24, 2024
f3aa68c
Try pylint 3.10
georgeyiasemis Jun 24, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
- uses: psf/black@22.12.0
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: ['3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: ['3.9', '3.10']

steps:
georgeyiasemis marked this conversation as resolved.
Show resolved Hide resolved
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Before you submit a pull request, check that it meets these guidelines:
#. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
#. The pull request should work for Python 3.8 and 3.9 and for PyPy. Check Github actions and see that all tests pass.
#. The pull request should work for Python 3.10 and for PyPy. Check Github actions and see that all tests pass.

Tests
^^^^^
Expand Down
4 changes: 2 additions & 2 deletions direct/common/_gaussian.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def gaussian_mask_1d(
int n,
int center,
double std,
cnp.ndarray[cnp.int_t, ndim=1, mode='c'] mask,
cnp.ndarray[cnp.int64_t, ndim=1, mode='c'] mask,
int seed,
):
cdef int count, ind
Expand All @@ -82,7 +82,7 @@ def gaussian_mask_2d(
int center_x,
int center_y,
cnp.ndarray[cnp.float_t, ndim=1, mode='c'] std,
cnp.ndarray[cnp.int_t, ndim=2, mode='c'] mask,
cnp.ndarray[cnp.int64_t, ndim=2, mode='c'] mask,
int seed,
):
cdef int count, indx, indy
Expand Down
6 changes: 3 additions & 3 deletions direct/common/_poisson.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def poisson(
int nx,
int ny,
int max_attempts,
cnp.ndarray[cnp.int_t, ndim=2, mode='c'] mask,
cnp.ndarray[cnp.int64_t, ndim=2, mode='c'] mask,
cnp.ndarray[cnp.float64_t, ndim=2, mode='c'] radius_x,
cnp.ndarray[cnp.float64_t, ndim=2, mode='c'] radius_y,
int seed
Expand All @@ -62,8 +62,8 @@ def poisson(
cdef Py_ssize_t startx, endx, starty, endy, px, py

# initialize active list
cdef cnp.ndarray[cnp.int_t, ndim=1, mode='c'] pxs = np.empty(nx * ny, dtype=int)
cdef cnp.ndarray[cnp.int_t, ndim=1, mode='c'] pys = np.empty(nx * ny, dtype=int)
cdef cnp.ndarray[cnp.int64_t, ndim=1, mode='c'] pxs = np.empty(nx * ny, dtype=int)
cdef cnp.ndarray[cnp.int64_t, ndim=1, mode='c'] pys = np.empty(nx * ny, dtype=int)

srand(seed)

Expand Down
46 changes: 32 additions & 14 deletions direct/data/datasets_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

"""Classes holding the typed configurations for the datasets."""

from __future__ import annotations

from dataclasses import dataclass
from typing import List, Optional, Tuple
from typing import Optional

from omegaconf import MISSING

Expand All @@ -14,6 +16,7 @@
MaskSplitterType,
RandomFlipType,
ReconstructionType,
RescaleMode,
SensitivityMapType,
TransformsType,
)
Expand All @@ -37,9 +40,17 @@ class SensitivityMapEstimationTransformConfig(BaseConfig):
sensitivity_maps_gaussian: Optional[float] = 0.7


@dataclass
class AugmentationTransformConfig(BaseConfig):
rescale: Optional[tuple[int, ...]] = None
rescale_mode: Optional[RescaleMode] = RescaleMode.NEAREST
rescale_2d_if_3d: Optional[bool] = False
pad: Optional[tuple[int, ...]] = None


@dataclass
class RandomAugmentationTransformsConfig(BaseConfig):
random_rotation_degrees: Tuple[int, ...] = (-90, 90)
random_rotation_degrees: tuple[int, ...] = (-90, 90)
random_rotation_probability: float = 0.0
georgeyiasemis marked this conversation as resolved.
Show resolved Hide resolved
random_flip_type: Optional[RandomFlipType] = RandomFlipType.RANDOM
random_flip_probability: float = 0.0
Expand All @@ -62,8 +73,10 @@ class TransformsConfig(BaseConfig):
Configuration for the masking.
cropping : CropTransformConfig
Configuration for the cropping.
augmentation : AugmentationTransformConfig
Configuration for the augmentation. Currently only rescale and pad are supported.
random_augmentations : RandomAugmentationTransformsConfig
Configuration for the random augmentations.
Configuration for the random augmentations. Currently only random rotation, flip and reverse are supported.
padding_eps : float
Padding epsilon. Default is 0.001.
estimate_body_coil_image : bool
Expand All @@ -79,6 +92,9 @@ class TransformsConfig(BaseConfig):
Default is True.
image_recon_type : ReconstructionType
Image reconstruction type. Default is ReconstructionType.RSS.
compress_coils : int, optional
Number of coils to compress input k-space. It is not recommended to be used in combination with `pad_coils`.
Default is None.
pad_coils : int, optional
Pad coils. Default is None.
use_seed : bool
Expand All @@ -89,10 +105,10 @@ class TransformsConfig(BaseConfig):
To use SSL transforms, set transforms_type to `SSL_SSDU`. This will require additional parameters to be set:
mask_split_ratio, mask_split_acs_region, mask_split_keep_acs, mask_split_type, mask_split_gaussian_std.
Default is `TransformsType.SUPERVISED`.
mask_split_ratio : Tuple[float, ...]
mask_split_ratio : tuple[float, ...]
Ratio of the mask to split into input and target mask. Ignored if transforms_type is not `SSL_SSDU`.
Default is (0.4,).
mask_split_acs_region : Tuple[int, int]
mask_split_acs_region : tuple[int, int]
Region of the ACS k-space to keep in the input mask. Ignored if transforms_type is not `SSL_SSDU`.
Default is (0, 0).
mask_split_keep_acs : bool, optional
Expand All @@ -111,6 +127,7 @@ class TransformsConfig(BaseConfig):

masking: Optional[MaskingConfig] = MaskingConfig()
cropping: CropTransformConfig = CropTransformConfig()
augmentation: AugmentationTransformConfig = AugmentationTransformConfig()
random_augmentations: RandomAugmentationTransformsConfig = RandomAugmentationTransformsConfig()
padding_eps: float = 0.001
estimate_body_coil_image: bool = False
Expand All @@ -119,12 +136,13 @@ class TransformsConfig(BaseConfig):
delete_acs_mask: bool = True
delete_kspace: bool = True
image_recon_type: ReconstructionType = ReconstructionType.RSS
compress_coils: Optional[int] = None
pad_coils: Optional[int] = None
use_seed: bool = True
transforms_type: TransformsType = TransformsType.SUPERVISED
# Next attributes are for the mask splitter in case of transforms_type is set to SSL_SSDU
mask_split_ratio: Tuple[float, ...] = (0.4,)
mask_split_acs_region: Tuple[int, int] = (0, 0)
mask_split_ratio: tuple[float, ...] = (0.4,)
mask_split_acs_region: tuple[int, int] = (0, 0)
mask_split_keep_acs: Optional[bool] = False
mask_split_type: MaskSplitterType = MaskSplitterType.GAUSSIAN
mask_split_gaussian_std: float = 3.0
Expand All @@ -146,21 +164,21 @@ class H5SliceConfig(DatasetConfig):
kspace_context: int = 0
pass_mask: bool = False
data_root: Optional[str] = None
filenames_filter: Optional[List[str]] = None
filenames_lists: Optional[List[str]] = None
filenames_filter: Optional[list[str]] = None
filenames_lists: Optional[list[str]] = None
filenames_lists_root: Optional[str] = None


@dataclass
class CMRxReconConfig(DatasetConfig):
regex_filter: Optional[str] = None
data_root: Optional[str] = None
filenames_filter: Optional[List[str]] = None
filenames_lists: Optional[List[str]] = None
filenames_filter: Optional[list[str]] = None
filenames_lists: Optional[list[str]] = None
filenames_lists_root: Optional[str] = None
kspace_key: str = "kspace_full"
compute_mask: bool = False
extra_keys: Optional[List[str]] = None
extra_keys: Optional[list[str]] = None
kspace_context: Optional[str] = None


Expand All @@ -181,11 +199,11 @@ class FakeMRIBlobsConfig(DatasetConfig):

@dataclass
class SheppLoganDatasetConfig(DatasetConfig):
shape: Tuple[int, int, int] = (100, 100, 30)
shape: tuple[int, int, int] = (100, 100, 30)
num_coils: int = 12
seed: Optional[int] = None
B0: float = 3.0
zlimits: Tuple[float, float] = (-0.929, 0.929)
zlimits: tuple[float, float] = (-0.929, 0.929)


@dataclass
Expand Down
Loading
Loading