mri-autoencoder-v0.1 / data_utils.py
pidajay's picture
Commited model weights and demo code
83e314f
import numpy as np
def complex_to_two_channel_image(complex_img: np.ndarray) -> np.ndarray:
"""Converts a complex valued image to a 2 channel image (real and imaginary channels)"""
real, imag = np.real(complex_img), np.imag(complex_img)
return np.concatenate((real, imag), axis=0)
def two_channel_to_complex_image(two_ch_img: np.ndarray) -> np.ndarray:
"""Converts a 2 channel image (real and imaginary channels) to a complex valued image"""
two_ch_img = two_ch_img[0]
real = two_ch_img[0]
imag = two_ch_img[1]
complex_image = real + 1j*imag
return complex_image[None,...]
def normalize_complex_coil_image(complex_coil_img: np.ndarray) -> np.ndarray:
"""Scales the complex valued coil image """
max_val = np.percentile(np.abs(complex_coil_img), 99.5)
return complex_coil_img / max_val
def create_three_channel_image(complex_coil_img: np.ndarray) -> np.ndarray:
"""Converts a complex valued coil image to a 3 channel image (magnitude channels repated 3 times)"""
mag = np.abs(complex_coil_img)
return np.concatenate((mag, mag, mag), axis=0)