Skip to content

ENH: Replace ExtractImageFilter with zero-copy sub-region extraction - #973

Open
axel-grc wants to merge 1 commit into
RTKConsortium:mainfrom
axel-grc:SubRegion
Open

ENH: Replace ExtractImageFilter with zero-copy sub-region extraction#973
axel-grc wants to merge 1 commit into
RTKConsortium:mainfrom
axel-grc:SubRegion

Conversation

@axel-grc

@axel-grc axel-grc commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Fix #91 : Replace itk::ExtractImageFilter with a lightweight free function that creates sub-region views by sharing the input buffer via SetImportPointer, avoiding pixel copies and filter pipeline overhead.

@axel-grc

axel-grc commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

I made some tests on FDK, the extract phase is at least 1000x faster, but it is still a very small part of the total reconstruction time (<1%).

@axel-grc
axel-grc force-pushed the SubRegion branch 3 times, most recently from f6972b5 to 6f747a5 Compare July 21, 2026 11:59

@SimonRit SimonRit left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works. The proposed solution only works if the extracted region corresponds to a contiguous memory region of the input. This is not always the case and there is a check missing for this. If it is not contiguous, there should be a fallback to itk::ExtractImageFilter.

Comment thread include/rtkExtractImageSubRegion.h Outdated
Comment on lines +108 to +118
#ifdef RTK_USE_CUDA
using TCudaImage = itk::CudaImage<PixelType, Dimension>;
if (TCudaImage * cudaOutput = dynamic_cast<TCudaImage *>(output.GetPointer()))
{
cudaOutput->GetModifiableDataManager()->SetBufferSize(numPixels * sizeof(PixelType));
cudaOutput->GetModifiableDataManager()->SetImagePointer(cudaOutput);
cudaOutput->GetModifiableDataManager()->SetCPUBufferPointer(const_cast<PixelType *>(bufferPtr));
cudaOutput->GetModifiableDataManager()->SetGPUDirtyFlag(true);
cudaOutput->GetModifiableDataManager()->SetCPUDirtyFlag(false);
}
#endif

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think CudaImage needs a specific case when dealing with CPU memory

When region is contiguous, replace itk::ExtractImageFilter with a lightweight free function
that creates sub-region views by sharing the input buffer via
SetImportPointer, avoiding pixel copies and filter pipeline overhead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Time is lost extracting each (substack of) projection(s) in the mini-pipeline

2 participants