Skip to content

Support streaming in Gaussian interpolate image function - #998

Merged
dzenanz merged 3 commits into
InsightSoftwareConsortium:masterfrom
dzenanz:gaussianInterpolate
Jun 7, 2019
Merged

dzenanz merged 3 commits into
InsightSoftwareConsortium:masterfrom
dzenanz:gaussianInterpolate

Conversation

@dzenanz

@dzenanz dzenanz commented Jun 6, 2019 •

Copy link
Copy Markdown
Member

Closes #988.

PR Checklist

@dzenanz

dzenanz commented Jun 6, 2019

Copy link
Copy Markdown
Member Author

OK, this needs a pass on Linux compiler compatibility. On it.

@dzenanz
dzenanz force-pushed the gaussianInterpolate branch from c68f083 to e6eaaaf Compare June 6, 2019 15:36
@dzenanz

dzenanz commented Jun 6, 2019

Copy link
Copy Markdown
Member Author

It passes the tests now. Please review.

@dzenanz
dzenanz requested a review from N-Dekker June 6, 2019 19:25
@hjmjohnson

Copy link
Copy Markdown
Member

@dzenanz Needs merge conflict resolution.

@dzenanz
dzenanz force-pushed the gaussianInterpolate branch from e6eaaaf to e6145f6 Compare June 6, 2019 19:53
@dzenanz
dzenanz force-pushed the gaussianInterpolate branch from e6145f6 to 8d9f21d Compare June 6, 2019 19:54

@romangrothausmann romangrothausmann left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many thanks @dzenanz for investigating this.
ITK compiles all fine in my test case and the streaming now runs without any errors but the result is not the same as without streaming, see the differing MD5s in e.g.
https://gitlab.com/romangrothausmann/ITK-CLIs_GL/-/jobs/226732768

@romangrothausmann

Copy link
Copy Markdown
Member

@dzenanz What is the reason why a random input image did not trigger this problem while ACN_speed.mhd does (#988 (comment))?

@dzenanz

dzenanz commented Jun 7, 2019

Copy link
Copy Markdown
Member Author

Maybe because I supplied .nhdr file, and NRRD does not support streaming even for reading? In retrospect, I should have paid more attention to that.

@dzenanz

dzenanz commented Jun 7, 2019

Copy link
Copy Markdown
Member Author

An updated code points out the differences. out4.mha file contains an additional field in the header: ElementSize = 1 1 1. If I copy this to out1.mha using a text editor, the files become identical.

#include <itkImageFileReader.h>
#include <itkResampleImageFilter.h>
#include <itkGaussianInterpolateImageFunction.h>
#include <itkImageFileWriter.h>

using ImageType = itk::Image<int, 3>;
using ReaderType = itk::ImageFileReader<ImageType>;
using FilterType = itk::ResampleImageFilter<ImageType, ImageType>;
using TransformType = itk::IdentityTransform<double, 3>;
using InterpolatorType = itk::GaussianInterpolateImageFunction<ImageType>;
using WriterType = itk::ImageFileWriter<ImageType>;

int main(int argc, char** argv)
{
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName(argv[1]);
    reader->UpdateOutputInformation();
    ImageType::Pointer input = reader->GetOutput();

    typename TransformType::Pointer transform = TransformType::New();
    transform->SetIdentity();
    typename ImageType::SpacingType outputSpacing;
    outputSpacing.Fill(1.0);

    FilterType::Pointer filter = FilterType::New();
    filter->SetInput(reader->GetOutput());
    filter->SetInterpolator(InterpolatorType::New());
    filter->SetSize(input->GetLargestPossibleRegion().GetSize());
    filter->SetOutputOrigin(input->GetOrigin());

    filter->SetTransform(transform);
    filter->SetOutputSpacing(outputSpacing);
    filter->SetOutputDirection(input->GetDirection());
    filter->SetDefaultPixelValue(0);
    filter->ReleaseDataFlagOn();

    WriterType::Pointer writer = WriterType::New();
    writer->SetInput(filter->GetOutput());
    try
    {
        writer->SetFileName("C:/Misc/Tester/out1.mha");
        writer->SetNumberOfStreamDivisions(1);
        writer->Update();

        writer->SetFileName("C:/Misc/Tester/out4.mha");
        writer->SetNumberOfStreamDivisions(4);
        writer->Update();
    }
    catch (itk::ExceptionObject& exc)
    {
        std::cout << exc;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

@romangrothausmann

Copy link
Copy Markdown
Member

additional field in the header:

That I do not observe to be the difference for the MD5s (tested with writing to MHDs: MHDs identical, MD5s of RAWs differ), instead output_SDI.mha contains only NaN from slice 65 onwards, which probably is the reason why stat for output_SDI.mha prints:

Min: -1.52596 Max: 1.42494 Mean: -nan Std: -nan Variance: -nan Sum: -nan

see: https://gitlab.com/romangrothausmann/ITK-CLIs/-/jobs/227298454

@dzenanz

dzenanz commented Jun 7, 2019

Copy link
Copy Markdown
Member Author

Well, how about you modify the current MWE to demonstrate the problem?

@romangrothausmann

Copy link
Copy Markdown
Member

Working on that (https://gitlab.com/romangrothausmann/ITK-CLIs/commits/debugGaussRes), with local testing I do get differing MD5s as soon as I put

    reader->ReleaseDataFlagOn();

in before reader->UpdateOutputInformation();

@romangrothausmann

Copy link
Copy Markdown
Member

However, removing reader->ReleaseDataFlagOn(); in resample.cxx (romangrothausmann/ITK-CLIs@378b839) does not make its test for Gauss succeed...
On the ohter hand, adding differing outputSpacing to the MWE (romangrothausmann/ITK-CLIs@1540e43) does not lead to differing MD5s on the RAWs.

@dzenanz

dzenanz commented Jun 7, 2019

Copy link
Copy Markdown
Member Author

The reader->ReleaseDataFlagOn(); makes only the least piece of the output have correct information, the rest is filled with junk. I think this is yet another, separate bug with streaming.

I will merge this PR, as it is a noticeable improvement (no crashing, works well without ReleaseDataFlagOn).

Can you create a new bug report, or even better a PR proposing a new test which demonstrates the problem with streaming+ReleaseDataFlagOn+GaussianInterpolateImageFunction? The MWE we have in this thread can be easily reworked into the desired regression test. Or perhaps update itkResampleImageTest7 to also test GaussianInterpolateImageFunction and ReleaseDataFlagOn?

@dzenanz
dzenanz merged commit 2d07018 into InsightSoftwareConsortium:master Jun 7, 2019
@dzenanz
dzenanz deleted the gaussianInterpolate branch June 7, 2019 15:23
@romangrothausmann

Copy link
Copy Markdown
Member

I will merge this PR, as it is a noticeable improvement (no crashing, works well without ReleaseDataFlagOn).

Approved.

Can you create a new bug report, or even better a PR proposing a new test which demonstrates the problem with streaming+ReleaseDataFlagOn+GaussianInterpolateImageFunction? The MWE we have in this thread can be easily reworked into the desired regression test. Or perhaps update itkResampleImageTest7 to also test GaussianInterpolateImageFunction and ReleaseDataFlagOn?

That, or similar, hope to find the time for continuing debugging next week.

out4.mha file contains an additional field in the header

What could be the reason for that? Even with romangrothausmann/ITK-CLIs@1540e43 the non-streaming output lack the entry ElementSize, which should not be the case.

@blowekamp

Copy link
Copy Markdown
Member

I have never used the ReleaseDataFlag with streaming before as when streaming the buffer is reused for the region processed. Is this a problem with just this combination or a general architecture problem with the data pipeline?

@blowekamp
blowekamp self-requested a review June 7, 2019 15:31
@romangrothausmann

romangrothausmann commented Jun 7, 2019 •

Copy link
Copy Markdown
Member

@blowekamp all other interpolators in my resampe.cxx seem to work all right with ReleaseDataFlag, it is only the Gauss Interpolator that causes trouble.
E.g. resamplers 0,1,2,5,20 all work: https://gitlab.com/romangrothausmann/ITK-CLIs/pipelines/65211704

@dzenanz

dzenanz commented Jun 7, 2019

Copy link
Copy Markdown
Member Author

I think I tried linear, and it worked correctly.

@romangrothausmann

Copy link
Copy Markdown
Member

Found a way to reproduce the problem, just scoping all and running the streaming separately: romangrothausmann/ITK-CLIs@eb81cb5
That way each MHD has its ElementSize and the RAWs differ (and yield exactly the same output as resample.cxx.

@romangrothausmann

romangrothausmann commented Jun 7, 2019 •

Copy link
Copy Markdown
Member

Not sure though why the version without scoping behaves differently. Could it be that the filter is not re-executed even though it has filter->ReleaseDataFlagOn();? Without that it would be necessary to outdate the filter (with input->Modified();) to have it re-execute for the streaming.

hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this pull request May 6, 2026
…nInterpolate

Support streaming in Gaussian interpolate image function
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this pull request May 12, 2026
…nInterpolate

Support streaming in Gaussian interpolate image function
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.

Error when resampling with Gaussian interpolation when employing streaming

4 participants