Skip to content

Commit

Permalink
Recon_surf and CerebNet API's
Browse files Browse the repository at this point in the history
  • Loading branch information
engrosamaali91 committed Feb 14, 2024
1 parent 8c20cca commit 9411c49
Show file tree
Hide file tree
Showing 16 changed files with 275 additions and 181 deletions.
44 changes: 43 additions & 1 deletion CerebNet/apply_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,63 @@
# limitations under the License.

# IMPORTS
from os.path import join
import numpy as np
import nibabel as nib

from os.path import join
from CerebNet.datasets import utils


def save_nii_image(img_data, save_path, header, affine):
"""
Save an image data array as a NIfTI file.
Parameters
----------
img_data : ndarray
The image data to be saved.
save_path : str
The path (including file name) where the image will be saved.
header : nibabel.Nifti1Header
The header information for the NIfTI file.
affine : ndarray
The affine matrix for the NIfTI file.
Returns
-------
None
This function returns nothing.
"""

img_out = nib.Nifti1Image(img_data, header=header, affine=affine)
print(f"Saving {save_path}")
nib.save(img_out, save_path)


def store_warped_data(img_path, lbl_path, warp_path, result_path, patch_size):

"""
Load, warp, crop, and save both an image and its corresponding label based on a given warp field.
Parameters
----------
img_path : str
Path to the T1-weighted MRI image to be warped.
lbl_path : str
Path to the label image corresponding to the T1 image, to be warped similarly.
warp_path : str
Path to the warp field file used to warp the images.
result_path : str
Directory path where the warped and cropped images will be saved.
patch_size : tuple of int
The dimensions (height, width, depth) cropped images after warping.
Returns
-------
None
This function returns nothing.
"""

img, img_file = utils.load_reorient_rescale_image(img_path)

lbl_file = nib.load(lbl_path)
Expand Down
12 changes: 7 additions & 5 deletions CerebNet/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

# IMPORTS
import time
import nibabel as nib
import numpy as np
import torch

from os import makedirs
from os.path import join, dirname, isfile
from typing import Dict, List, Tuple, Optional
from concurrent.futures import Future, ThreadPoolExecutor

import nibabel as nib
import numpy as np
import torch
from torch.utils.data import DataLoader
from tqdm import tqdm

from FastSurferCNN.utils import logging
from FastSurferCNN.utils.threads import get_num_threads
from FastSurferCNN.utils.mapper import JsonColorLookupTable, TSVLookupTable
Expand All @@ -44,6 +43,9 @@


class Inference:
"""
Manages inference operations, including batch processing, data loading, and model predictions for neuroimaging data.
"""
def __init__(
self,
cfg: "yacs.ConfigNode",
Expand Down
21 changes: 21 additions & 0 deletions CerebNet/run_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@


def setup_options():
"""
Configure and return an argument parser for the segmentation script.
Returns
-------
argparse.ArgumentParser
The configured argument parser.
"""
# Training settings
parser = argparse.ArgumentParser(description="Segmentation")

Expand Down Expand Up @@ -94,6 +102,19 @@ def setup_options():


def main(args):
"""
Main function to run the inference based on the given command line arguments.
Parameters
----------
args : argparse.Namespace
Command line arguments parsed by `argparse.ArgumentParser`.
Returns
-------
str or None
A message indicating the failure reason in case of an exception, otherwise `None`.
"""
cfg = get_config(args)
cfg.TEST.ENABLE = True
cfg.TRAIN.ENABLE = False
Expand Down
2 changes: 1 addition & 1 deletion doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ FastSurfer API
FastSurferCNN.utils.rst
FastSurferCNN.data_loader.rst
recon_surf.rst

CerebNet.rst
11 changes: 11 additions & 0 deletions doc/api/recon_surf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ API recon_surf References
align_points
align_seg
create_annotation
fs_balabels
lta
map_surf_label
N4_bias_correct
paint_cc_into_pred
rewrite_mc_surface
rotate_sphere
sample_parc
smooth_aparc
spherically_project_wrapper




2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import os
sys.path.append(os.path.dirname(__file__) + '/..')
sys.path.append(os.path.dirname(__file__) + '/../recon_surf')
# sys.path.append(os.path.dirname(__file__) + '/../CerebNet')

# sys.path.insert(0, '..') #after

# autodoc_mock_imports = ["torch", "yacs"]
Expand Down
Loading

0 comments on commit 9411c49

Please sign in to comment.