Skip to content

Commit 9d3494c

Browse files
committed
- modify mrd tools scripts of stream_recon and mrd_image_stream_to_png to support frequency dimension from MRD to ISMRMRD and vice versa.
- update MRD-ISMRMRD converters to take the image of 0th frequency dimension of MRD format to ISMRMRD to ignore frequency dimension, which has not equilvalence in ISMRMRD format. - add cflags overwrite to avoid fortify_source error - add version check for setuptools on meta.yaml to avoid setuptools.build_meta import failures.
1 parent 0374c43 commit 9d3494c

13 files changed

Lines changed: 28 additions & 18 deletions

File tree

cpp/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ project(mrd VERSION ${MRD_VERSION_STRING})
1616

1717
message(STATUS "MRD_VERSION_STRING: ${MRD_VERSION_STRING}")
1818

19-
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
20-
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
19+
# if flags are already set, don't override them
20+
if (NOT DEFINED CMAKE_CXX_FLAGS_DEBUG)
21+
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
22+
endif ()
23+
if (NOT DEFINED CMAKE_C_FLAGS_DEBUG)
24+
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
25+
endif ()
2126

2227
#Set the build type to Release if not specified
2328
if (NOT CMAKE_BUILD_TYPE)

cpp/mrd-tools/converters.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,8 @@ ISMRMRD::Image<T> convert(mrd::Image<T>& image) {
10541054
for (int z = 0; z < im.getMatrixSizeZ(); z++) {
10551055
for (int y = 0; y < im.getMatrixSizeY(); y++) {
10561056
for (int x = 0; x < im.getMatrixSizeX(); x++) {
1057-
// ISMRMRD does not support frequency dimension from MRD image
1058-
// Take 0th image on frequency dimension from MRD to ISMRMRD
1057+
// MRD supports frequency as extra dimension, which does not exist in ISMRMRD format
1058+
// Take 0th image on frequency dimension from MRD to convert to ISMRMRD
10591059
im(x, y, z, c) = image.data(c, z, y, x, 0);
10601060
}
10611061
}
@@ -2063,8 +2063,8 @@ mrd::Image<T> convert(ISMRMRD::Image<T>& im) {
20632063
image.head.user_float.push_back(im.getUserFloat(i));
20642064
}
20652065

2066-
// Add an extra singleton dimension from ISMRMRD to represent (channel, z, y, x, frequency) dimensions for MRD image
2067-
mrd::ImageData<T> data({im.getNumberOfChannels(), im.getMatrixSizeZ(), im.getMatrixSizeY(), im.getMatrixSizeX(), 0});
2066+
// Add an extra singleton dimension to represent (channel, z, y, x, frequency) dimensions for MRD image
2067+
mrd::ImageData<T> data({im.getNumberOfChannels(), im.getMatrixSizeZ(), im.getMatrixSizeY(), im.getMatrixSizeX(), 1});
20682068
for (int c = 0; c < im.getNumberOfChannels(); c++) {
20692069
for (int z = 0; z < im.getMatrixSizeZ(); z++) {
20702070
for (int y = 0; y < im.getMatrixSizeY(); y++) {

cpp/mrd-tools/mrd_stream_recon.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int main(int argc, char** argv) {
187187
}
188188
slice = fftshift(slice);
189189

190-
std::array<size_t, 4> image_shape = {1, slice.shape(1), slice.shape(2), slice.shape(3)};
190+
std::array<size_t, 5> image_shape = {1, slice.shape(1), slice.shape(2), slice.shape(3), 1}; // singleton frequency dimension added
191191
auto pixel_data = xt::sqrt(xt::abs(xt::sum(slice * xt::conj(slice), 0)));
192192

193193
auto xoffset = (slice.shape(3) + 1) / 2 - (rNx + 1) / 2;
@@ -200,7 +200,7 @@ int main(int argc, char** argv) {
200200

201201
mrd::Image<float> im;
202202
im.data = xt::zeros<float>(image_shape);
203-
xt::view(im.data, 0, xt::all(), xt::all(), xt::all()) = combined;
203+
xt::view(im.data, 0, xt::all(), xt::all(), xt::all(), 0) = combined;
204204

205205
im.head.measurement_uid = acq.head.measurement_uid;
206206
im.head.field_of_view[0] = rFOVx;

cpp/mrd/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ struct Image {
985985
return yardl::shape(data, 3);
986986
}
987987

988-
yardl::Size Freqs() const {
988+
yardl::Size Frequencies() const {
989989
return yardl::shape(data, 4);
990990
}
991991

matlab/toolbox/+mrd/Image.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
return
4949
end
5050

51-
function res = freqs(self)
51+
function res = frequencies(self)
5252
res = size(self.data, ndims(self.data)-(4));
5353
return
5454
end

model/mrd_image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Image<T>: !record
9898
slices: size(data, "z")
9999
rows: size(data, "y")
100100
cols: size(data, "x")
101-
freqs: size(data, "frequency")
101+
frequencies: size(data, "frequency")
102102

103103
ImageUint16: Image<uint16>
104104
ImageInt16: Image<int16>

python/conda/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ requirements:
1616
build:
1717
- python
1818
- pip
19+
- setuptools >=65.5.0
1920
run:
2021
- python
2122
- ismrmrd-python >=1.14.2

python/mrd/tools/export_png_images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def export(input, output, verbose=False):
2020

2121
for c in range(image.channels()):
2222
for s in range(image.slices()):
23-
im = Image.fromarray(pixels[c, s, :, :], 'L')
23+
im = Image.fromarray(pixels[c, s, :, :, 0], 'L') # 0th idx to ignore frequency dimension
2424
filename = f"{output}{image_count:05d}.png"
2525
im.save(filename, format='PNG')
2626
if verbose:

python/mrd/tools/ismrmrd_to_mrd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def convert_image(ismrmrd_img: ismrmrd.Image) -> mrd.StreamItem:
514514
# If parsing fails, skip meta
515515
pass
516516

517-
data = ismrmrd_img.data
517+
data = np.expand_dims(ismrmrd_img.data, axis=-1) # add frequency dimension from ISMRMRD to MRD on the last axis
518518
dtype = data.dtype
519519
if dtype == np.uint16:
520520
img = mrd.Image[np.uint16](head=out_head, data=data.astype(np.uint16), meta=meta)

python/mrd/tools/mrd_to_ismrmrd.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,12 @@ def convert_image(mrd_img) -> ismrmrd.Image:
481481
mrd_head = mrd_img.head
482482
data = mrd_img.data
483483

484-
# Get dimensions: data is (channels, z, y, x)
484+
# Get dimensions: data is (channels, z, y, x, frequencies)
485485
channels = data.shape[0]
486486
z = data.shape[1]
487487
y = data.shape[2]
488488
x = data.shape[3]
489+
frequencies = data.shape[4] # no equivalence in ISMRMRD
489490

490491
# Build the ImageHeader first
491492
head = ismrmrd.ImageHeader()
@@ -585,7 +586,7 @@ def convert_image(mrd_img) -> ismrmrd.Image:
585586
# Note: resize signature is (nc, nz, ny, nx) - same order as MRD!
586587
img.resize(channels, z, y, x)
587588
img.setHead(head)
588-
img.data[:] = data
589+
img.data[:] = data[..., 0] # Take 0th frequency dimension from mrd to ISMRMRD
589590

590591
# Set attribute_string if present
591592
if attribute_string:

0 commit comments

Comments
 (0)