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

Zoom image from template method for ImageData #1285

Open
wants to merge 6 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
22 changes: 20 additions & 2 deletions src/xSTIR/cSTIR/cstir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ void* cSTIR_newObject(const char* name)
return NEW_OBJECT_HANDLE(RayTracingMatrix);
if (sirf::iequals(name, "SPECTUBMatrix"))
return NEW_OBJECT_HANDLE(SPECTUBMatrix);
#if STIR_VERSION >= 050100
if (sirf::iequals(name, "PinholeSPECTUBMatrix"))
return NEW_OBJECT_HANDLE(PinholeSPECTUBMatrix);
#endif
if (sirf::iequals(name, "QuadraticPrior"))
return NEW_OBJECT_HANDLE(QuadPrior3DF);
if (sirf::iequals(name, "LogcoshPrior"))
Expand All @@ -205,8 +203,14 @@ void* cSTIR_newObject(const char* name)
if (sirf::iequals(name, "PETScatterEstimator"))
return NEW_OBJECT_HANDLE(PETScatterEstimator);
if (sirf::iequals(name, "SeparableGaussianImageFilter"))


return NEW_OBJECT_HANDLE(xSTIR_SeparableGaussianImageFilter);


return unknownObject("object", name, __FILE__, __LINE__);


}
CATCH;
}
Expand Down Expand Up @@ -1511,6 +1515,20 @@ void* cSTIR_ImageData_zoom_image(void* ptr_im, const size_t zooms_ptr_raw, const
CATCH;
}

extern "C"
void* cSTIR_ImageData_zoom_image_from_template(void* zoomed_image_ptr, void* original_image_ptr, const char *const zoom_options) {
try {
STIRImageData& zoomed_id = objectFromHandle<STIRImageData>(zoomed_image_ptr);
STIRImageData& original_id = objectFromHandle<STIRImageData>(original_image_ptr);

// Use the in_id image as the template for zooming
zoomed_id.zoom_image(original_id, zoom_options);

return static_cast<void*>(new DataHandle);
}
CATCH;
}

extern "C"
void* cSTIR_ImageData_move_to_scanner_centre(void* im_ptr, const void* acq_data_ptr)
{
Expand Down
3 changes: 3 additions & 0 deletions src/xSTIR/cSTIR/include/sirf/STIR/cstir.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ extern "C" {
const PTR_FLOAT offsets_in_mm_ptr_raw,
const PTR_INT new_sizes_ptr_raw,
const char * const zoom_options);
void* cSTIR_ImageData_zoom_image_from_template(void* zoomed_image_ptr,
const void* original_image_ptr,
const char * const zoom_options);
void* cSTIR_ImageData_move_to_scanner_centre(void* im_ptr, const void* acq_data_ptr);
void* cSTIR_computeKernelisedImage(void* ptr_r, void* ptr_i, void* ptr_a);

Expand Down
6 changes: 6 additions & 0 deletions src/xSTIR/cSTIR/include/sirf/STIR/stir_data_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,12 @@ namespace sirf {
const Coord3DI& new_sizes = { -1,-1,-1 },
const stir::ZoomOptions zoom_options = stir::ZoomOptions::preserve_sum);

void zoom_image(const STIRImageData& original_image,
const stir::ZoomOptions zoom_options = stir::ZoomOptions::preserve_sum);

void zoom_image(const STIRImageData& original_image,
const char* const zoom_options_str = "preserve_sum");

/// Move to scanner centre. The acquisition needs to be supplied such that in the future,
/// bed offset etc can be taken into account.
void move_to_scanner_centre(const STIRAcquisitionData&);
Expand Down
41 changes: 40 additions & 1 deletion src/xSTIR/cSTIR/stir_data_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,6 @@ zoom_image(const Coord3DF &zooms, const Coord3DF &offsets_in_mm,
// Need to modify the geom info after changing size
set_up_geom_info();
}

void
STIRImageData::
zoom_image(const Coord3DF &zooms, const Coord3DF &offsets_in_mm,
Expand All @@ -812,6 +811,46 @@ zoom_image(const Coord3DF &zooms, const Coord3DF &offsets_in_mm,
set_up_geom_info();
}

void
STIRImageData::
zoom_image(const STIRImageData& template_image, stir::ZoomOptions zoom_options)
{
SIRF_DYNAMIC_CAST(Voxels3DF, image_voxels, this->data());
SIRF_DYNAMIC_CAST(const Voxels3DF, template_voxels, template_image.data());

// Zoom the image
stir::zoom_image(image_voxels, template_voxels, zoom_options);

// Need to modify the geom info after changing size
set_up_geom_info();
}

void
STIRImageData::
zoom_image(const STIRImageData& original_image, const char *zoom_options_str)
{

stir::ZoomOptions zoom_options;
if (strcmp(zoom_options_str,"preserve_sum")==0)
zoom_options = stir::ZoomOptions::preserve_sum;
else if (strcmp(zoom_options_str,"preserve_values")==0)
zoom_options = stir::ZoomOptions::preserve_values;
else if (strcmp(zoom_options_str,"preserve_projections")==0)
zoom_options = stir::ZoomOptions::preserve_projections;
else
throw std::runtime_error("zoom_image: unknown scaling option - " + std::string(zoom_options_str));

SIRF_DYNAMIC_CAST(Voxels3DF, zoomed_voxels, this->data());
SIRF_DYNAMIC_CAST(const Voxels3DF, original_voxels, original_image.data());

// Zoom the image
stir::zoom_image(zoomed_voxels, original_voxels, zoom_options);

// Need to modify the geom info after changing size
set_up_geom_info();
}


void
STIRImageData::
move_to_scanner_centre(const STIRAcquisitionData &)
Expand Down
19 changes: 18 additions & 1 deletion src/xSTIR/pSTIR/STIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,24 @@ def zoom_image(self, zooms=(1., 1., 1.), offsets_in_mm=(0., 0., 0.),
np_offsets_in_mm.ctypes.data, np_size.ctypes.data, scaling))

return zoomed_im

def zoom_image_from_template(self, template, scaling='preserve_sum'):
"""
Returns a zoomed image based on a template image's geometry.
Supported scaling options are: 'preserve_sum', 'preserve_values' and
'preserve_projections'
"""

zoomed_image = template.clone()

if not isinstance(template, ImageData):
raise error('zoom_image_from_template: template should be ImageData')

### becaus of a bug somewherre
try_calling(pystir.cSTIR_ImageData_zoom_image_from_template(
zoomed_image.handle, self.handle, scaling))

return zoomed_image

def move_to_scanner_centre(self, proj_data):
"""Moves the image to the scanner centre.
Expand Down Expand Up @@ -3456,7 +3474,6 @@ def get_objective_function(self):
check_status(obj_fun.handle)
return obj_fun


class SingleScatterSimulator():
'''
Class for simulating the scatter contribution to PET data.
Expand Down
Loading