Created
June 28, 2018 16:15
-
-
Save dedmari/683f4a9150c64f04d088a96dbbea0808 to your computer and use it in GitHub Desktop.
JPEG200_MRI_Compression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import h5py | |
import glymur | |
def image_space_save_as_jpg2000(in_dir, out_dir): | |
""" | |
:param file_name: image_space file name for compression i.e. 58 x 640 x 129 x 240; 58 coils, oversampled x-axis by factor 2, | |
zero value removed y axis, z are number of slices | |
:param out_dir: output dir for storing imaginary and real parts of image space | |
""" | |
compression_ratio = [5] | |
file_name = in_dir | |
file_name += "original_img_space_oversampled_without_grappa.h5" | |
img_space_file = h5py.File(file_name, "r") | |
img_space_matrix = img_space_file["imgspace"] | |
data = np.array(img_space_matrix) | |
## Normalizing the intensity scale | |
for c in range(0, img_space_matrix.shape[0]): | |
print("creating files for coil: ", c) | |
for slice in range(0, img_space_matrix.shape[3]): | |
one_slice = data[c, :, :, slice] | |
real_min_val = np.amin(one_slice.real) | |
real_max_val = np.amax(one_slice.real) | |
imag_min_val = np.amin(one_slice.imag) | |
imag_max_val = np.amax(one_slice.imag) | |
one_slice.real -= real_min_val | |
one_slice.real /= (real_max_val - real_min_val) | |
one_slice.imag -= imag_min_val | |
one_slice.imag /= (imag_max_val - imag_min_val) | |
real_part = img_as_uint(one_slice.real) | |
imag_part = img_as_uint(one_slice.imag) | |
print("real_part data type: ", real_part.dtype) | |
print("imaginary part data typ: ", imag_part.dtype) | |
jp2 = glymur.Jp2k(out_dir + str(c) + "_" + str(slice) + "_real.jp2", data=real_part, cratios=compression_ratio) | |
jp2 = glymur.Jp2k(out_dir + str(c) + "_" + str(slice) + "_imag.jp2", data=imag_part, cratios=compression_ratio) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment