Giter Site home page Giter Site logo

image-x-institute / mri_distortion_toolkit Goto Github PK

View Code? Open in Web Editor NEW
2.0 0.0 3.0 26.76 MB

Characterisation and reporting of geometric distortion in MRI

Home Page: https://image-x-institute.github.io/mri_distortion_toolkit/

License: GNU General Public License v3.0

Python 2.96% CSS 2.35% Makefile 0.01% Batchfile 0.01% HTML 94.25% JavaScript 0.43%
mri mri-qa mri-distortion reporting spherical-harmonics magnetic-resonance-imaging

mri_distortion_toolkit's People

Contributors

bwheelz36 avatar natalielbbh avatar paulzyliu avatar

Stargazers

 avatar

mri_distortion_toolkit's Issues

harmonics need to be scaled for gradient strength!!

Ok this is a pretty dumb thing to not realise, but at the moment my harmonics are not accounting for different gradient strengths.

So, I will implement a scaling to 1 mT/m in the calculate Bz step, then in the distortion correction step, we can scale the encoding fields according to the harmonics

Not getting good results segmenting the tutorial CT data

I don't think the math is quite right here.. I will try to fix.. I want to add an iterative approach anyway

marker_size_lower_tol=0.9, marker_size_upper_tol=1

# Set up min and max marker volumes based on expected number of markers
n_voxels_median = np.median(np.array(n_voxels))
voxel_min = (1-self._marker_size_lower_tol) * n_voxels_median
voxel_max = (1+self._marker_size_upper_tol) * n_voxels_median

This code is currently giving this for the CT data:

Median marker volume: 748.0
Expected marker volume: 74.79999999999998 to 1496.0

(Too many markers found at the moment)

add this to utilities

def calculate_harmonics(forward_volume, back_volume, n_order=8):
    # match the markers
    matched_markers = MatchedMarkerVolumes(ct_volume, forward_volume, sorting_method='radial', ReferenceMarkers=11,
                                              WarpSearchData=True, ReverseGradientData=back_volume)
    matched_markers.MatchedCentroids.to_csv('MatchedMarkerVolume.csv')

    # calculate B fields
    B_fields = ConvertMatchedMarkersToBz(matched_markers.MatchedCentroids, forward_volume.dicom_data)

    # calculate harmonics
    # B0
    B0_data = B_fields.MagneticFields[['x', 'y', 'z', 'B0']]
    B0_data = B0_data.rename(
        columns={"B0": "Bz"})  # spherical harmonics code expects to receieve one field called Bz
    B0_Harmonics = SphericalHarmonicFit(B0_data, n_order=n_order, r_outer=150)
    # Gx
    GradXdata = B_fields.MagneticFields[['x', 'y', 'z', 'B_Gx']]
    GradXdata = GradXdata.rename(
        columns={"B_Gx": "Bz"})  # spherical harmonics code expects to receieve one field called Bz
    G_x_Harmonics = SphericalHarmonicFit(GradXdata, n_order=n_order, r_outer=150)
    G_x_Harmonics.harmonics.to_csv('G_x_harmonics.csv')
    # Gy
    GradYdata = B_fields.MagneticFields[['x', 'y', 'z', 'B_Gy']]
    GradYdata = GradYdata.rename(
        columns={"B_Gy": "Bz"})  # spherical harmonics code expects to receieve one field called Bz
    G_y_Harmonics = SphericalHarmonicFit(GradYdata, n_order=n_order, r_outer=150)
    G_y_Harmonics.harmonics.to_csv('G_y_harmonics.csv')
    # G_z
    GradZdata = B_fields.MagneticFields[['x', 'y', 'z', 'B_Gz']]
    GradZdata = GradZdata.rename(
        columns={"B_Gz": "Bz"})  # spherical harmonics code expects to receieve one field called Bz
    G_z_Harmonics = SphericalHarmonicFit(GradZdata, n_order=n_order, r_outer=150)
    G_z_Harmonics.harmonics.to_csv('G_z_harmonics.csv')

    return B0_Harmonics, G_x_Harmonics, G_y_Harmonics, G_z_Harmonics

Auto export to slicer

At the moment, the code automatically exports to slicer (makes the slicer_centroids.mrk.json file and overwrites the old one) each time the segmentation is run.

I think this should be a user run function? Like run the segmentation, then if it looks right, export to slicer? You could overwrite a 'correct' segmentation with a wrong one if you're playing around with the parameters

Fix logger message

In marker analysis
logger.warning('failed to extract phase encoding
should be frequency

Typo in tutorial

In the marker matching section

'# ground truth centroids ground_truth_volume = MarkerVolume(data_loc / 'CT' / 'MR.mrk.json', verbose=False)`

MR.mrk.json should be slicer_centroids.mrk.json

Add to utilities?

def enumerate_subfolders(data_loc):
    data_dict = {}
    subfolders = [ f.path for f in os.scandir(data_loc) if f.is_dir() ]
    for i, dir in enumerate(subfolders):
        folder_name = os.path.split(dir)[1]
        data_dict[str(i)] = folder_name
    for key in data_dict.keys():
        print(f"'{key}': '{data_dict[key]}',")

Error when segmenting CT

Need to skip this when segmenting CT because there's no bandwidth tag

self._calculate_gradient_strength()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.