Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scatter Estimation / Sinogram interpolation in 3D #1156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/buildblock/extend_projdata.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ namespace detail

Array<3,float>
extend_segment_in_views(const SegmentBySinogram<float>& sino,
const int min_view_extension, const int max_view_extension)
const int min_view_extension, const int max_view_extension,
const SegmentBySinogram<float>& inv_sino)
{
if (sino.get_segment_num()!=0)
error("extend_segment with single segment works only for segment 0");
// if (sino.get_segment_num()!=0)
// error("extend_segment with single segment works only for segment 0");

BasicCoordinate<3,int> min, max;

Expand All @@ -138,7 +139,7 @@ extend_segment_in_views(const SegmentBySinogram<float>& sino,
{
out[ax_pos_num] =
detail::
extend_sinogram_in_views(sino[ax_pos_num],sino[ax_pos_num],
extend_sinogram_in_views(sino[ax_pos_num],inv_sino[ax_pos_num],
*(sino.get_proj_data_info_sptr()),
min_view_extension, max_view_extension);
}
Expand All @@ -147,14 +148,15 @@ extend_segment_in_views(const SegmentBySinogram<float>& sino,

Array<2,float>
extend_sinogram_in_views(const Sinogram<float>& sino,
const int min_view_extension, const int max_view_extension)
const int min_view_extension, const int max_view_extension,
const Sinogram<float>& inv_sino)
{
if (sino.get_segment_num()!=0)
error("extend_segment with single segment works only for segment 0");
// if (sino.get_segment_num()!=0)
// error("extend_segment with single segment works only for segment 0");

return
detail::
extend_sinogram_in_views(sino, sino,
extend_sinogram_in_views(sino, inv_sino,
*(sino.get_proj_data_info_sptr()),
min_view_extension, max_view_extension);
}
Expand Down
373 changes: 361 additions & 12 deletions src/buildblock/interpolate_projdata.cxx

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/buildblock/scale_sinograms.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ scale_sinograms(


Array<2,float>
get_scale_factors_per_sinogram(const ProjData& numerator_proj_data,
get_scale_factors_per_sinogram(const ProjData& numerator_proj_data,
const ProjData& denominator_proj_data,
const ProjData& weights_proj_data)
{
Expand Down Expand Up @@ -116,7 +116,7 @@ get_scale_factors_per_sinogram(const ProjData& numerator_proj_data,
{
warning("Problem at segment %d, axial pos %d in finding sinogram scaling factor.\n"
"Weighted data in denominator %g is very small compared to total in sinogram %g.\n"
"Adjust weights?.\n"
"Adjust weights?. This could be an axial gap.\n"
"I will use scale factor %g",
bin.segment_num(),bin.axial_pos_num(),
total_in_denominator[bin.segment_num()][bin.axial_pos_num()],
Expand Down
6 changes: 4 additions & 2 deletions src/include/stir/extend_projdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ This is probably only useful before calling interpolation routines, or for FORE.
*/
Array<3,float>
extend_segment_in_views(const SegmentBySinogram<float>& sino,
const int min_view_extension, const int max_view_extension);
const int min_view_extension, const int max_view_extension,
const SegmentBySinogram<float>& inv_sino);
Array<2,float>
extend_sinogram_in_views(const Sinogram<float>& sino,
const int min_view_extension, const int max_view_extension);
const int min_view_extension, const int max_view_extension,
const Sinogram<float>& inv_sino);
//@}

END_NAMESPACE_STIR
Expand Down
15 changes: 11 additions & 4 deletions src/include/stir/interpolate_projdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
START_NAMESPACE_STIR

class ProjData;
class ProjDataInfo;
template <int num_dimensions, class T> class BasicCoordinate;
template <class elemT> class Sinogram;
template <class elemT> class SegmentBySinogram;
Expand Down Expand Up @@ -51,16 +52,22 @@ template <class elemT> class SegmentBySinogram;
//@{
Succeeded
interpolate_projdata(ProjData& proj_data_out,
const ProjData& proj_data_in,
const BSpline::BSplineType spline_type,
const shared_ptr<ProjData> proj_data_in,
const BSpline::BSplineType& spline_type,
const bool remove_interleaving = false,
const bool use_view_offset = false);
Succeeded
interpolate_projdata(ProjData& proj_data_out,
const ProjData& proj_data_in,
const shared_ptr<ProjData> proj_data_in,
const BasicCoordinate<3, BSpline::BSplineType> & spline_type,
const bool remove_interleaving = false,
const bool use_view_offset = false);
const bool use_view_offset = false);

Succeeded
interpolate_projdata_3d(shared_ptr<ProjData> projdata_out,
const shared_ptr<ProjData> projdata_in_sptr,
const BSpline::BSplineType & spline_type,
const bool use_view_offset = false);
//@}

END_NAMESPACE_STIR
Expand Down
9 changes: 9 additions & 0 deletions src/include/stir/numerics/sampling_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

*/

#include "stir/Array.h"
#include "stir/common.h"
START_NAMESPACE_STIR

/*!
Expand Down Expand Up @@ -49,6 +51,13 @@ void sample_function_on_regular_grid(Array<3,elemT>& out,
const BasicCoordinate<3, positionT>& offset,
const BasicCoordinate<3, positionT>& step);

template <class FunctionType, class elemT, class positionT>
inline
void sample_function_on_regular_grid(Array<2,elemT>& out,
FunctionType func,
const BasicCoordinate<2, positionT>& offset,
const BasicCoordinate<2, positionT>& step);

END_NAMESPACE_STIR

#include "stir/numerics/sampling_functions.inl"
58 changes: 48 additions & 10 deletions src/include/stir/numerics/sampling_functions.inl
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,64 @@ void sample_function_on_regular_grid(Array<3,elemT>& out,
BasicCoordinate<3, positionT> relative_positions;
index_out[1]=min_out[1];
relative_positions[1]= index_out[1] * step[1] - offset[1] ;
const BasicCoordinate<3, positionT> max_relative_positions=
(BasicCoordinate<3,positionT>(max_out)+static_cast<positionT>(.001)) * step + offset;
const BasicCoordinate<3, positionT> max_relative_positions=
(BasicCoordinate<3,positionT>(max_out)+static_cast<positionT>(.001)) * step + offset;
for (;
index_out[1]<=max_out[1] && relative_positions[1]<=max_relative_positions[1];
++index_out[1], relative_positions[1]+= step[1])
{
{
index_out[2]=min_out[2];
relative_positions[2]= index_out[2] * step[2] + offset[2] ;
relative_positions[2]= index_out[2] * step[2] + offset[2] ;
for (;
index_out[2]<=max_out[2] && relative_positions[2]<=max_relative_positions[2];
++index_out[2], relative_positions[2]+= step[2])
{
{
index_out[3]=min_out[3];
relative_positions[3]= index_out[3] * step[3] + offset[3] ;
relative_positions[3]= index_out[3] * step[3] + offset[3] ;
for (;
index_out[3]<=max_out[3] && relative_positions[3]<=max_relative_positions[3];
++index_out[3], relative_positions[3]+= step[3])
out[index_out] = func(relative_positions) ;
}
}
++index_out[3], relative_positions[3]+= step[3])
{
out[index_out] = func(relative_positions) ;
}
}
}
}

template <class FunctionType, class elemT, class positionT>
void sample_function_on_regular_grid(Array<2,elemT>& out,
FunctionType func,
const BasicCoordinate<2, positionT>& offset,
const BasicCoordinate<2, positionT>& step)
{
BasicCoordinate<2,int> min_out, max_out;
IndexRange<2> out_range = out.get_index_range();

if (!out_range.get_regular_range(min_out,max_out))
warning("Output must be regular range!");

// in_total = out.sum();
BasicCoordinate<2, int> index_out;
BasicCoordinate<2, positionT> relative_positions;
index_out[1] = min_out[1];
relative_positions[1] = index_out[1] * step[1] - offset[1] ;

const BasicCoordinate<2, positionT> max_relative_positions=
(BasicCoordinate<2,positionT>(max_out)+static_cast<positionT>(.001)) * step + offset;
for (;
index_out[1]<=max_out[1] && relative_positions[1]<=max_relative_positions[1];
++index_out[1], relative_positions[1]+= step[1])
{
index_out[2]=min_out[2];
relative_positions[2]= index_out[2] * step[2] + offset[2] ;
for (;
index_out[2]<=max_out[2] && relative_positions[2]<=max_relative_positions[2];
++index_out[2], relative_positions[2]+= step[2])
{

out[index_out] = func(relative_positions) ;
}
}
}

END_NAMESPACE_STIR
5 changes: 3 additions & 2 deletions src/include/stir/scatter/ScatterEstimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ class ScatterEstimation: public ParsingObject
static void
upsample_and_fit_scatter_estimate(ProjData& scaled_scatter_proj_data,
const ProjData& emission_proj_data,
const ProjData& scatter_proj_data,
shared_ptr<ProjData> scatter_proj_data,
BinNormalisation& scatter_normalisation,
const ProjData& weights_proj_data,
const float min_scale_factor,
const float max_scale_factor,
const unsigned half_filter_width,
BSpline::BSplineType spline_type = BSpline::BSplineType::linear,
const bool remove_interleaving = true);
const bool remove_interleaving = true,
const bool do_3D = false);


//! Default constructor (calls set_defaults())
Expand Down
Loading