Repository navigation
PERF: Use scanline iterators in per-pixel filter loops #7258
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
Changes from all commits
c05aa6c
4ef33db
3828551
480b533
9692af0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |||||||
| #include "itkConstantBoundaryCondition.h" | ||||||||
| #include "itkOffset.h" | ||||||||
| #include "itkProgressReporter.h" | ||||||||
| #include "itkTotalProgressReporter.h" | ||||||||
| #include "itkMath.h" | ||||||||
| #include "itkPrintHelper.h" | ||||||||
|
|
||||||||
|
|
@@ -75,10 +76,9 @@ BinaryDilateImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData() | |||||||
| // Support progress methods/callbacks | ||||||||
| // Setup a progress reporter. We have 4 stages to the algorithm so | ||||||||
| // pretend we have 4 times the number of pixels | ||||||||
| ProgressReporter progress(this, | ||||||||
| 0, | ||||||||
| outputRegion.GetNumberOfPixels() * 2 + tmpRequestedRegion.GetNumberOfPixels() + | ||||||||
| requiredInputRegion.GetNumberOfPixels()); | ||||||||
| TotalProgressReporter progress(this, | ||||||||
| outputRegion.GetNumberOfPixels() * 2 + tmpRequestedRegion.GetNumberOfPixels() + | ||||||||
| requiredInputRegion.GetNumberOfPixels()); | ||||||||
|
|
||||||||
| // Allocate and reset output. We copy the input to the output, | ||||||||
| // except for pixels with DilateValue. These pixels are initially | ||||||||
|
|
@@ -100,8 +100,8 @@ BinaryDilateImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData() | |||||||
| { | ||||||||
| outIt.Set(static_cast<OutputPixelType>(value)); | ||||||||
| } | ||||||||
| progress.CompletedPixel(); | ||||||||
| } | ||||||||
| progress.Completed(outputRegion.GetNumberOfPixels()); | ||||||||
|
|
||||||||
| // Create the temp image for surface encoding | ||||||||
| // The temp image size is equal to the output requested region for thread | ||||||||
|
|
@@ -158,8 +158,8 @@ BinaryDilateImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData() | |||||||
| // it as background | ||||||||
| tmpRegIt.Set(backgroundTag); | ||||||||
| } | ||||||||
| progress.CompletedPixel(); | ||||||||
| } | ||||||||
| progress.Completed(requiredInputRegion.GetNumberOfPixels()); | ||||||||
|
|
||||||||
| // Second stage | ||||||||
| // Border tracking and encoding | ||||||||
|
|
@@ -451,6 +451,9 @@ BinaryDilateImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData() | |||||||
| progress.CompletedPixel(); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // The border tracking stage reports fewer pixels than it was allotted. | ||||||||
| this->UpdateProgress(1.0f); | ||||||||
|
Comment on lines
+455
to
+456
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: two small points on the Greptile fix, which is needed (
Suggested change
Reasoned from the code, not run. |
||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,10 +21,12 @@ | |||||||
| #include "itkImageRegionIteratorWithIndex.h" | ||||||||
| #include "itkNeighborhoodInnerProduct.h" | ||||||||
| #include "itkImageRegionConstIterator.h" | ||||||||
| #include "itkImageScanlineIterator.h" | ||||||||
| #include "itkNeighborhoodAlgorithm.h" | ||||||||
| #include "itkConstantBoundaryCondition.h" | ||||||||
| #include "itkOffset.h" | ||||||||
| #include "itkProgressReporter.h" | ||||||||
| #include "itkTotalProgressReporter.h" | ||||||||
| #include "itkMath.h" | ||||||||
| #include "itkPrintHelper.h" | ||||||||
|
|
||||||||
|
|
@@ -75,10 +77,9 @@ BinaryErodeImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData() | |||||||
| // Support progress methods/callbacks | ||||||||
| // Setup a progress reporter. We have 4 stages to the algorithm so | ||||||||
| // pretend we have 4 times the number of pixels | ||||||||
| ProgressReporter progress(this, | ||||||||
| 0, | ||||||||
| outputRegion.GetNumberOfPixels() * 3 + tmpRequestedRegion.GetNumberOfPixels() + | ||||||||
| requiredInputRegion.GetNumberOfPixels()); | ||||||||
| TotalProgressReporter progress(this, | ||||||||
| outputRegion.GetNumberOfPixels() * 3 + tmpRequestedRegion.GetNumberOfPixels() + | ||||||||
| requiredInputRegion.GetNumberOfPixels()); | ||||||||
|
|
||||||||
| // Allocate and reset output. We copy the input to the output, | ||||||||
| // except for pixels with DilateValue. These pixels are initially | ||||||||
|
|
@@ -90,8 +91,8 @@ BinaryErodeImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData() | |||||||
| for (outIt.GoToBegin(); !outIt.IsAtEnd(); ++outIt) | ||||||||
| { | ||||||||
| outIt.Set(foregroundValue); | ||||||||
| progress.CompletedPixel(); | ||||||||
| } | ||||||||
| progress.Completed(outputRegion.GetNumberOfPixels()); | ||||||||
|
|
||||||||
| // Create the temp image for surface encoding | ||||||||
| // The temp image size is equal to the output requested region for thread | ||||||||
|
|
@@ -148,8 +149,8 @@ BinaryErodeImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData() | |||||||
| // it as background | ||||||||
| tmpRegIt.Set(backgroundTag); | ||||||||
| } | ||||||||
| progress.CompletedPixel(); | ||||||||
| } | ||||||||
| progress.Completed(requiredInputRegion.GetNumberOfPixels()); | ||||||||
|
|
||||||||
| // Second stage | ||||||||
| // Border tracking and encoding | ||||||||
|
|
@@ -447,18 +448,25 @@ BinaryErodeImageFilter<TInputImage, TOutputImage, TKernel>::GenerateData() | |||||||
| } | ||||||||
|
|
||||||||
| // now, we must to restore the background values | ||||||||
| ImageRegionConstIterator inIt(input, outputRegion); | ||||||||
| ImageScanlineConstIterator inIt(input, outputRegion); | ||||||||
| ImageScanlineIterator outLineIt(output, outputRegion); | ||||||||
|
|
||||||||
| for (inIt.GoToBegin(), outIt.GoToBegin(); !outIt.IsAtEnd(); ++outIt, ++inIt) | ||||||||
| for (; !outLineIt.IsAtEnd(); outLineIt.NextLine(), inIt.NextLine()) | ||||||||
| { | ||||||||
| const InputPixelType inValue = inIt.Get(); | ||||||||
| const OutputPixelType outValue = outIt.Get(); | ||||||||
| if (Math::ExactlyEquals(outValue, backgroundValue) && Math::NotExactlyEquals(inValue, foregroundValue)) | ||||||||
| for (; !outLineIt.IsAtEndOfLine(); ++outLineIt, ++inIt) | ||||||||
| { | ||||||||
| outIt.Set(static_cast<OutputPixelType>(inValue)); | ||||||||
| const InputPixelType inValue = inIt.Get(); | ||||||||
| const OutputPixelType outValue = outLineIt.Get(); | ||||||||
| if (Math::ExactlyEquals(outValue, backgroundValue) && Math::NotExactlyEquals(inValue, foregroundValue)) | ||||||||
| { | ||||||||
| outLineIt.Set(static_cast<OutputPixelType>(inValue)); | ||||||||
| } | ||||||||
| } | ||||||||
| progress.CompletedPixel(); | ||||||||
| progress.Completed(outputRegion.GetSize(0)); | ||||||||
| } | ||||||||
|
|
||||||||
| // The border tracking stage reports fewer pixels than it was allotted. | ||||||||
| this->UpdateProgress(1.0f); | ||||||||
|
Comment on lines
+468
to
+469
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: same as on BinaryDilate: the comment wording, and the second
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.