Skip to content

Commit

Permalink
fixed max for strictly negative data, fixes #1234
Browse files Browse the repository at this point in the history
  • Loading branch information
evgueni-ovtchinnikov committed Feb 19, 2024
1 parent f17f050 commit a323b88
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/Registration/cReg/NiftiImageData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,8 +1762,9 @@ void NiftiImageData<dataType>::sum(void* ptr) const
template<class dataType>
void NiftiImageData<dataType>::max(void* ptr) const
{
float s = 0.0;
for (unsigned i = 0; i < this->_nifti_image->nvox; ++i) {
unsigned i = 0;
float s = _data[i++];
for (; i < this->_nifti_image->nvox; ++i) {
float si = _data[i];
if (si > s)
s = si;
Expand Down
12 changes: 9 additions & 3 deletions src/xGadgetron/cGadgetron/gadgetron_data_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,15 @@ MRAcquisitionData::max(const ISMRMRD::Acquisition& acq_a)
{
const complex_float_t* pa;
complex_float_t z = 0;
bool init = true;
for (pa = acq_a.data_begin(); pa != acq_a.data_end(); pa++) {
complex_float_t zi = *pa;
float r = std::real(z);
float ri = std::real(zi);
if (ri > r)
if (init || ri > r) {
z = zi;
init = false;
}
}
return z;
}
Expand Down Expand Up @@ -626,6 +629,7 @@ MRAcquisitionData::max(void* ptr) const
int n = number();
complex_float_t z = 0;
ISMRMRD::Acquisition a;
bool init = true;
for (int i = 0; i < n;) {
if (!get_acquisition(i, a)) {
i++;
Expand All @@ -634,8 +638,10 @@ MRAcquisitionData::max(void* ptr) const
complex_float_t zi = MRAcquisitionData::max(a);
float r = std::real(z);
float ri = std::real(zi);
if (ri > r)
if (init || ri > r) {
z = zi;
init = false;
}
i++;
}
complex_float_t* ptr_z = static_cast<complex_float_t*>(ptr);
Expand Down Expand Up @@ -1459,7 +1465,7 @@ GadgetronImageData::max(void* ptr) const
complex_float_t zi = wi.max();
float r = std::real(z);
float ri = std::real(zi);
if (ri > r)
if (i == 0 || ri > r)
z = zi;
}
complex_float_t* ptr_z = static_cast<complex_float_t*>(ptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ namespace sirf {
complex_float_t si = (complex_float_t)*i;
float r = std::real(*s);
float ri = std::real(si);
if (ri > r)
if (ii == 0 || ri > r)
*s = si;
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/xSTIR/cSTIR/stir_data_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,19 @@ STIRAcquisitionData::max(void* ptr) const
{
int n = get_max_segment_num();
float t = 0;
bool init = true;
TOF_LOOP
for (int s = 0; s <= n; ++s)
{
SegmentBySinogram<float> seg = get_segment_by_sinogram(s TOF_ARG);
SegmentBySinogram<float>::full_iterator seg_iter;
for (seg_iter = seg.begin_all(); seg_iter != seg.end_all();)
t = std::max(t, *seg_iter++);
if (init) {
t = *seg_iter++;
init = false;
}
else
t = std::max(t, *seg_iter++);
if (s != 0) {
seg = get_segment_by_sinogram(-s TOF_ARG);
for (seg_iter = seg.begin_all(); seg_iter != seg.end_all();)
Expand Down Expand Up @@ -482,9 +488,9 @@ STIRImageData::max(void* ptr) const
#else
typename Array<3, float>::const_full_iterator iter;
#endif

float s = 0.0;
for (iter = data().begin_all(); iter != data().end_all(); iter++)
iter = data().begin_all();
float s = *iter++;
for (; iter != data().end_all(); iter++)
s = std::max(s, *iter);
float* ptr_s = static_cast<float*>(ptr);
*ptr_s = (float)s;
Expand Down

0 comments on commit a323b88

Please sign in to comment.