Git Product home page Git Product logo

Comments (2)

mariusarvinte avatar mariusarvinte commented on August 24, 2024

Thanks for your questions, we measured PSNR and SSIM using the metrics:

from skimage.metrics import structural_similarity as ssim
from skimage.metrics import peak_signal_noise_ratio as psnr

They are imported in https://github.com/utcsilab/csgm-mri-langevin/blob/main/plot-demo.ipynb, but seems like we didn't include a clear example, sorry about that. We compared the magnitude images using SSIM and PSNR.

The ground-truth was the complex-valued MVUE image obtained from the raw fastMRI kspace data, by first properly resizing it to a square size. Given that the ground-truth MVUE requires sensitivity maps, we used the BART toolbox to estimate them - https://mrirecon.github.io/bart/.

The sparse measurements were taken from this resized kspace, and our posterior sampling returns a square, complex-valued image of the same shape as the ground truth. For example, for the fastMRI T2 brain @ 3T axial dataset, we first resized the kspace to 384 x 384; we used a 1D FFT to resize the x-axis, and a crop on the y-axis (the x-axis is ~768 in the raw kspace data; the y-axis is >= 384).

I'll follow up with exact code snippets once I retrieve them, let us know if there are any other questions in the meantime.

from csgm-mri-langevin.

mariusarvinte avatar mariusarvinte commented on August 24, 2024

Here is the exact code we used to estimate sensitivity maps s_maps from the raw fastMRI files via the BART toolbox Python API:

import sys
sys.path.insert(0, 'your/path/to/bart/python')
from bart import bart

# Load kspace from file
file = 'your/file/here.h5'
with h5py.File(file, 'r') as data:
    # Get kspace
    kspace= np.asarray(data['kspace'])

# Number of ACS lines
acs_lines = 12
(num_slices, num_coils, img_h, img_w) = kspace.shape

# Output maps
s_maps = np.zeros((num_slices, num_coils, img_h, img_w),
              dtype=np.complex64)

# For each slice
for idx in tqdm(range(num_slices)):
    # ACS
    num_cols = k_image.shape[-1]
    acs_idx    = np.arange(num_cols //2 - acs_lines//2,
                           num_cols //2 + acs_lines//2)

    # Remove everything except ACS
    k_down = np.zeros(k_image.shape)
    k_down[..., acs_idx] = k_image[..., acs_idx]
    
    # Estimate maps from ACS region
    s_maps[idx] = bart(1, 'ecalib -m1 -W -c0', 
                k_down.transpose((1, 2, 0))[None,...]).transpose(
                    (3, 1, 2, 0)).squeeze()

The other processing of kspace that I mentioned previously can be found e.g. for T2 brain here:

# Crop extra lines and reduce FoV in phase-encode
gt_ksp = sp.resize(gt_ksp, (
gt_ksp.shape[0], gt_ksp.shape[1], self.image_size[1]))
# Reduce FoV by half in the readout direction
gt_ksp = sp.ifft(gt_ksp, axes=(-2,))
gt_ksp = sp.resize(gt_ksp, (gt_ksp.shape[0], self.image_size[0],
gt_ksp.shape[2]))
gt_ksp = sp.fft(gt_ksp, axes=(-2,)) # Back to k-space
# Crop extra lines and reduce FoV in phase-encode
maps = sp.fft(maps, axes=(-2, -1)) # These are now maps in k-space
maps = sp.resize(maps, (
maps.shape[0], maps.shape[1], self.image_size[1]))
# Reduce FoV by half in the readout direction
maps = sp.ifft(maps, axes=(-2,))
maps = sp.resize(maps, (maps.shape[0], self.image_size[0],
maps.shape[2]))
maps = sp.fft(maps, axes=(-2,)) # Back to k-space
maps = sp.ifft(maps, axes=(-2, -1)) # Finally convert back to image domain
# find mvue image
mvue = get_mvue(gt_ksp.reshape((1,) + gt_ksp.shape), maps.reshape((1,) + maps.shape))

Now one can use kspace and paired s_maps and run any reconstruction algorithm that results in a coil-combined image e.g. as in here: https://github.com/utcsilab/csgm-mri-langevin/blob/91e0a5ac658feaf6460045706ef16dd140894374/main.py#L198C37-L198C37

Finally, we used the SSIM and PSNR from scikit.metrics as:

from skimage.metrics import structural_similarity as ssim_loss
from skimage.metrics import peak_signal_noise_ratio as psnr_loss

ssim = ssim_loss(np.abs(gt_mvue), np.abs(estimated_mvue), data_range=np.abs(gt_mvue).max())
psnr = psnr_loss(np.abs(gt_mvue), np.abs(estimated_mvue), data_range=np.abs(gt_mvue).max())

from csgm-mri-langevin.

Related Issues (6)

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.