Skip to content

Commit

Permalink
Fixes a bug in NiftiImageData.cpp causing segfault (#1226)
Browse files Browse the repository at this point in the history
* fixed a bug in NiftiImageData.cpp causing segfault, fixes #1225

* moved conversion of complex images to NiftyResampler.norm()

* eliminated side effect in Reg.NiftyResampler.norm()

* attended to codacy issues
  • Loading branch information
evgueni-ovtchinnikov authored Jan 8, 2024
1 parent 20f9ad5 commit e650e29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Registration/cReg/NiftiImageData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void NiftiImageData<dataType>::construct_NiftiImageData_from_complex_im_real_com

auto &it_in = in_sptr->begin();
auto &it_out = out_sptr->begin();
for (; it_in!=in_sptr->end(); ++it_in, ++it_out)
for (; it_out != out_sptr->end(); ++it_in, ++it_out)
*it_out = (*it_in).complex_float().real();
}

Expand All @@ -235,7 +235,7 @@ void NiftiImageData<dataType>::construct_NiftiImageData_from_complex_im_imag_com

auto &it_in = in_sptr->begin();
auto &it_out = out_sptr->begin();
for (; it_in!=in_sptr->end(); ++it_in, ++it_out)
for (; it_out != out_sptr->end(); ++it_in, ++it_out)
*it_out = (*it_in).complex_float().imag();
}

Expand Down
16 changes: 16 additions & 0 deletions src/Registration/pReg/Reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,10 +1108,26 @@ def set_padding_value(self, val):
def norm(self, num_iter=2, verb=0):
'''Computes the norm of the forward projection operator.
'''
# reference and floating images need to be real.
if self.reference_image.is_complex():
reference_image, _ = NiftiImageData.construct_from_complex_image(self.reference_image)
parms.set_parameter(
self.handle, self.name, 'reference_image', reference_image.handle)
if self.floating_image.is_complex():
floating_image, _ = NiftiImageData.construct_from_complex_image(self.floating_image)
parms.set_parameter(
self.handle, self.name, 'floating_image', floating_image.handle)
handle = pyreg.cReg_NiftyResampler_norm(self.handle, num_iter, verb)
check_status(handle)
r = pyiutil.floatDataFromHandle(handle)
pyiutil.deleteDataHandle(handle)
# Restore reference and floating images.
if self.reference_image.is_complex():
parms.set_parameter(
self.handle, self.name, 'reference_image', self.reference_image.handle)
if self.floating_image.is_complex():
parms.set_parameter(
self.handle, self.name, 'floating_image', self.floating_image.handle)
return r;

def process(self):
Expand Down

0 comments on commit e650e29

Please sign in to comment.